Skip to content
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

One to Many, Many to Many #16

Open
virtualbrown opened this issue Feb 2, 2020 · 9 comments
Open

One to Many, Many to Many #16

virtualbrown opened this issue Feb 2, 2020 · 9 comments
Labels
feature New feature or request help wanted Extra attention is needed
Projects

Comments

@virtualbrown
Copy link

Thoughts on supporting Foreign Key field and many to many fields?

@rvinzent
Copy link
Owner

rvinzent commented Feb 2, 2020

Those features would be quite nice, and I would love to see them implemented! I'm having a hard time finding time to dedicate to this project at the moment though. PRs are welcome!

@virtualbrown
Copy link
Author

ok. So sounds like conceptually this is doable within the current framework of django-dynamic-models.

Is the right way to do this by adding a new DATA_TYPE in FieldFactory and the associated implementation?

@rvinzent
Copy link
Owner

Yea, it should be doable. There are other considerations that need to be taken into account for these fields though compared to the simpler data types.

@ghost
Copy link

ghost commented Mar 25, 2020

@virtualbrown any progress on implementing Foreign Key? Is adding a new DATA_TYPE right way to do this?

@rvinzent rvinzent added feature New feature or request help wanted Extra attention is needed labels May 17, 2020
@rvinzent
Copy link
Owner

rvinzent commented May 17, 2020

@macieyn

any progress on implementing Foreign Key? Is adding a new DATA_TYPE right way to do this?

0.2.0 was finally released today., and this feature unfortunately didn't make it in, but it is definitely on the roadmap. Check out the new API, and PRs are always welcome 😄

@rvinzent rvinzent added this to To do in Features via automation May 17, 2020
@rvinzent rvinzent added the 0.3.0 label May 17, 2020
@rvinzent rvinzent removed the 0.3.0 label Sep 21, 2020
@adavoudi
Copy link
Contributor

Hi @rvinzent

I want to work on this feature. Would you please tell me what are the considerations that need to be taken into account for these fields?

@rvinzent
Copy link
Owner

rvinzent commented Dec 18, 2020

HI @adavoudi thanks for your interest! I have been struggling to find the time to implement some of these features.

There are a few things that might make this a bit challenging given the current architecture. The kwargs for generated Field classes are currently each stored as DB column on FieldSchema. ManyToMany and ForeignKey each have a special set of kwargs that only apply to those fields, so I don't think it would be very scalable or easy to implement if we simply added more fields to the model.

I think there is a more proper refactoring we can do that should allow any field class (including custom fields) to be used. Instead of storing the data_type on the FieldSchema model and mapping this to a Field class, we should instead change this to be qualified class name of the field class to use. Then, instead of listing out each kwarg as a separate model field, we can replace all of that with a JSONField that can hold any necessary kwargs to construct the field.

The new FieldSchema should look something like this:

class FieldSchema(models.Model):
    name = models.CharField(max_length=63)
    model_schema = models.ForeignKey(ModelSchema, on_delete=models.CASCADE, related_name="fields")
    class_name = models.TextField()
    kwargs = models.JSONField(default=dict)

The new factory implementation should first import the field class by passing class_name to importlib, and then construct the field instance like field_class(**field_schema.kwargs).

Let me know if you have any questions, and if you're not up for the task I will do my best to prioritize this :)

@adavoudi
Copy link
Contributor

@rvinzent Great tips. I will work on this and ask for your guides if needed.

@saileshkush95
Copy link

Can you please explain how can i use new field schema, because documentation is not updated yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed
Projects
Features
  
To do
Development

No branches or pull requests

4 participants