Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Enabling spatial support into model mommy #94

Closed
wants to merge 5 commits into from
Closed

Enabling spatial support into model mommy #94

wants to merge 5 commits into from

Conversation

george-silva
Copy link

Hello @vandersonmota.

This is a great project, but in my day to day work uses a lot of geospatial information, so I need model_mommy to generate spatial data as well.

This a first draft that includes a point generator, using the already consolidated formulaes used by model_mommy.

In here I've updated the association between a field type and generators and created the spatial generator.

perhaps there are other ways to handle this, but let me know.

@vandersonmota
Copy link
Collaborator

Do you intend to add tests? ;-)

@george-silva
Copy link
Author

Hi @vandersonmota! Yes I do :D. I'm actually creating them right now inside the app I'll be using the modified model_mommy. I saw that the travis build failed.

Let me correct everything and I'll resubmit it.

@vandersonmota
Copy link
Collaborator

Ok. thank you!

@george-silva
Copy link
Author

@vandersonmota Hello vanderson, can you please review the tests I've made? They all pass, for now.

I still plan to determine the min and max x,y based on SRID and set that accordingly. I've also needed to change get_required_values in the mommy class to set the required parameters.

https://github.com/sigma-consultoria/model_mommy/blob/735f76786347faa94be608ca2dd4d38b58108a42/model_mommy/mommy.py#L352-L364

Oh, there's a catch, that I'm not sure how to solve: the testing database now needs to point to a PostGIS database. I'm sure we can change that to look for sqlite3 with spatial support, but that will not be optimum for all cases. We might need find a way to generate two database configurations, one with spatial support and other with no spatial support. Perhaps, that will need to be done inside the mommy class as well, I'm not sure if django will throw an error if the database backend does not have spatial support (even if it's just for testing).

Please, let me know what you think. Later on I plan to extend this to support LineStrings and Polygons.

Adding information about the spatial generators.
@vandersonmota
Copy link
Collaborator

@george-silva I'm thinking that maybe spatial support should be better as an extension of model_mommy, since it handles a very specific case. It will be easier to test and will not burden model_mommy tests (setup a PostGIS)

And it can be configured using: https://github.com/vandersonmota/model_mommy#custom-fields

More thoughts?

@george-silva
Copy link
Author

Ahhhhh! Great. It will be much easier to handle using custom fields.

I'll see if I can revert the changes and create those extensions.

@vandersonmota
Copy link
Collaborator

Tell me when the extension is ready, so i'll add a reference in the README.

@vandersonmota
Copy link
Collaborator

Closing PR since it will be made as an extension. Let me know when you're done.

Thanks!

@philippeluickx
Copy link

@george-silva Any news on adding this as an extension? I am definitely interested, as I am also using model mommy with a geospatial database...

Thanks!

@george-silva
Copy link
Author

@philippeluickx hello phillipe. Nice to see some interest.

I'll see if I can do this today.

@philippeluickx
Copy link

@george-silva Cool! Good luck and thanks in advance!

@vandersonmota
Copy link
Collaborator

and @george-silva tell us when it's ready. I'll link to it on readme.

Cheers!

@george-silva
Copy link
Author

@philippeluickx and @vandersonmota : i did some quick changes and created a new repository for this extension. This needs packaging, but for now you can clone from git and it should be fine. Please let me know if this helped.

https://github.com/sigma-consultoria/mommy_spatial_generators

@philippeluickx
Copy link

@george-silva Great, thanks for putting this up!
Not sure on how an extension works (or should work), but for now I simply copied to code to a seperate file in my settings folder. Works fair enough for me though!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants