berinhard / model_mommy

No longer maintained, please migrate to model_bakery
http://model-bakery.readthedocs.org/
Other
903 stars 141 forks source link

GeoDjango GeometryField throwing error #256

Closed steinbachr closed 6 years ago

steinbachr commented 9 years ago

Stack Trace:

Traceback (most recent call last):
  File "/rukkus/transaction/tests/test_models.py", line 24, in setUp
    self.user = mommy.make('buyer.User')
  File "/usr/local/lib/python2.7/dist-packages/model_mommy/mommy.py", line 96, in make
    return mommy.make(**attrs)
  File "/usr/local/lib/python2.7/dist-packages/model_mommy/mommy.py", line 294, in make
    return self._make(commit=True, **attrs)
  File "/usr/local/lib/python2.7/dist-packages/model_mommy/mommy.py", line 344, in _make
    model_attrs[field.name] = self.generate_value(field)
  File "/usr/local/lib/python2.7/dist-packages/model_mommy/mommy.py", line 452, in generate_value
    raise TypeError('%s is not supported by mommy.' % field.__class__)
TypeError: <class 'django.contrib.gis.db.models.fields.GeometryField'> is not supported by mommy.
vandersonmota commented 9 years ago

@steinbachr Indeed, we'll take a look soon. Meanwhile, you could create a recipe for that. http://model-mommy.readthedocs.org/en/latest/recipes.html

steinbachr commented 9 years ago

awesome, thanks @vandersonmota. I actually just ended up using the MOMMY_CUSTOM_FIELDS_GEN as a shim like so:

def mommy_timedelta_field():
    import datetime
    return datetime.timedelta(days=0)

def mommy_geometry_field():
    from django.contrib.gis.geos import Point
    return Point(0, 0)

MOMMY_CUSTOM_FIELDS_GEN = {
    'django.contrib.gis.db.models.fields.GeometryField': mommy_geometry_field,
    'timedelta.fields.TimedeltaField': mommy_timedelta_field,
}
dyve commented 8 years ago

Maybe just pull this in for GeoDjango (would be much appreciated since we use GeoDjango everywhere) https://github.com/sigma-geosistemas/mommy_spatial_generators

dyve commented 8 years ago

Is there any progress on this? Django with spatial fields is extremely common, and model-mommy would be better off supporting those fields. I have used both a self-written recipe as the generators from sigma-geosistema's, both work with mommy.

dyve commented 7 years ago

If there is still interest in adding this to the core of mommy, I'd be happy to submit a Pull Request. Please let me know.