Hi Sergey,

I was also wondering why GenericForeignKey don't have direct subclass of 
ForeignKey while writing a dep about field API improvement. Though I am not 
100% sure your implementation.

Thanks for bringing it up.



On Wednesday, April 5, 2017 at 2:46:31 AM UTC+6, Sergey Fedoseev wrote:
>
> Hi all,
>
> Some time ago I created 'new feature` ticket 
> <https://code.djangoproject.com/ticket/27580> and Tim Graham asked me to 
> write here to get some feedback on the idea. So here it is.
>
> ContentType model is quite specific, so we could add the subclass of 
> ForeignKey with some specific features.
>
>
> For example, we have a model:
>
>
> class ModelWithContentType(models.Model):
>     ct = ContentTypeField(on_delete=models.CASCADE)
>  
>
> In comparison with ForeignKey ContentTypeField will have these features:
>
>    1. ModelWithContentType.objects.first().ct will use content types 
>    cache 
>
>
>    1. ContentTypeField will support lookups on the model classes (on 
>    model instances too?):
>
> ModelWithContentType.objects.filter(ct=FooModel) vs.
>
>
> ModelWithContentType.objects.filter(ct=ContentType.objects.get_for_model(FooModel))
>
>
> ModelWithContentType.objects.filter(ct__in=[FooModel, BarModel]) vs.
> ModelWithContentType.objects.filter(ct__in=[ContentType.objects.get_for_model(model)
>  
> in [FooModel, BarModel]])
>
>    1. Creation using a model class as a value (not sure if it's useful 
>    actually): 
>
> ModelWithContentType.objects.create(ct=FooModel)
>
>
> Here's ​rough implementation 
> <https://github.com/sir-sigurd/django/tree/contenttype-field-3>.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/0764f9bc-be05-47ac-8201-b419a93d3061%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to