New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fields are not filled #9
Comments
Hi think I've fixed the blank string issue. Does v1.0.3 fixes the issue for you? Re: |
I tested #8 and it does indeed fill the fields. Traceback is:
My model does not have a slug, though one of the foreign key does. |
Odd, I've tried the same scenario (a model with a FK to a model with a From the stacktrace looks like the build process is crossing a FK relationship 3 times ( |
After a bit of digging I think I understand why there is an issue but I don't know how to solve it. I have two models both using AutoSlug like so from autoslug import AutoSlugField
def populate(self):
if hasattr(self, "title"):
return self.title
else:
return self.name
class AnotherModel(models.Model):
name = models.CharField(max_length=40)
slug = AutoSlugField(populate_from=populate)
class AModel(models.Model):
title = models.CharField(max_length=40)
another_model = models.ForeignKey(AnotherModel)
slug = AutoSlugField(populate_from=populate) When trying to fake AModel, it fails with myapp.AnotherModel.slug From my understanding, the code in values.py tries to create the model when encountering a foreign key if isinstance(field, models.ForeignKey):
return self.factory.make_one(get_related_model(field), iteration=self.iteration) Since it does not know what to do with an autoslug it fails. It can be solved for the first model by defining the slug but I don't see a way to do that for the related model. # This call works
myModel = factory.make(
'myapp.AnotherModel',
fields={
'title': lambda n, f: f.name(),
'slug': lambda n, f: f.word(),
}
)
# This call fails
factory.make(
'myapp.AModel',
fields={
'title': lambda n, f: f.name(),
'slug': lambda n, f: f.word(),
'another_model': myModel
}
) I have tried blueprints with no success. |
I see a couple of bugs here:
|
Nice, just tested and it worked. Thank you! 🙇 |
I'm having trouble using the package overall.
If we take the user model, it doesn't seem to want to save any other parameter than the username.
e.g:
It does create a user but it has no city, just a blank string :( It is a custom user model for info.
I tried with another model but it keeps wanting to fill a slug which does not exist on this model.
The text was updated successfully, but these errors were encountered: