paulocheque / django-dynamic-fixture

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

Generate model instance that contains custom fields #36

Closed shymonk closed 4 years ago

shymonk commented 10 years ago

I have a model contains ListField(custom field) like this:

class CalendarField(models.TextField):
     __metaclass__ = models.SubfieldBase 
     ...
    def to_python(self, value):
         if isinstance(value, list) or value is None:
            return value
         return [int(e) for e in value.split(self.token)]

class MyModel(models.Model):
    calendar = CalendarField()

When i use G() method to create instance:

m = G(MyModel, calendar=[1, 2, 3])

It always failed when executing to_python. After some debuging , i found that DDF filled calendar field with " " instead of [1, 2, 3].

So, my question is: How to fill custom field in G()?

I have looked over the document and tried several approaches, but they didn't help.

paulocheque commented 10 years ago

Strange behavior. I have recently merge a PR that deals with multiple inheritance that can affect this behavior, but it can be another issue too. If you have some PR I would be happy to merge!

paulocheque commented 4 years ago

I added more tests for custom fields too. If you have an example in how to reproduce this issue, please attach here. Thanks! @shymonk