models.Foreignkey(User) is a more pythonic and allows more better analysis
by tools like flake8, but in some cases you need to create the ForeignKey
before User is defined, so you _have_ to use a string. Example:

https://docs.djangoproject.com/en/stable/ref/models/fields/#foreignkey

On Sat, Apr 6, 2019 at 11:53 PM Mohit Solanki <mohitsolanki...@gmail.com>
wrote:

> Since Django allows specifying relationship between models by both as a
> string or by a model class
> "models.Foreignkey('User') vs "models.Foreignkey(User)". Which one is
> preferred and recommend and what are the downsides of choosing one over the
> other? In documentation all the examples are of the second form but i have
> seen ppl specifying relationships in string. Can someone please elaborate
> more on this?
>
> Regards,
> Mohit Solanki
>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> 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/CAKB6Ln-4rU2c%3DZL%3DTCbYfFZWG8fSDq4KP9DYhUc4TDFLNFdQtw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CAKB6Ln-4rU2c%3DZL%3DTCbYfFZWG8fSDq4KP9DYhUc4TDFLNFdQtw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/CAFO84S6m4aog8bm0gwJ14K4wH4x7o-DsYk1Hf2MqSmic6qgESw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to