paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
390 stars 67 forks source link

If a ForeignKey has a pk as its default value rather than an instance, dynamic fixtures break #20

Closed AndrewIngram closed 11 years ago

AndrewIngram commented 11 years ago

I have a model like this (heavily simplified):

class City(models.Model):
    currency = models.ForeignKey('payment.Currency', default=2)

If I try to create a city fixture using G(City), it fails because it attempts to assign 2 as the value of currency, rather than the instance of Currency with primary key 2

I think the solution is alter _process_field_with_default_fixture to return the foreign key's model if there's a default value that's not an instance or callable.

Admittedly, using defaults on relationship fields is a yucky, which we'll hopefully remove in the long run, but we'd like to be able to use DDF before then.

AndrewIngram commented 11 years ago

We'd also need to create the model instance with the specified default foreignkey if it doesn't already exsist.

paulocheque commented 11 years ago

Hi. I think this is a duplicated issue. Check my last comment in https://github.com/paulocheque/django-dynamic-fixture/issues/5

Regards

tobych commented 11 years ago

I just wrote another comment in #5. I filed that ticket then dropped the ball. I've now responded!