Thursday, September 1, 2016

Re: Disadvantages of using model name rather than model class for FK field?

Class might be easier to use for beginner and is explicit. There is an
import, you know what you are dealing with and you get clear error
when you do things wrong.

If you have circular depencencies, using model name can be the only solution.
If you have model A with a foreign key on model B and model B with a
foreign key on model A, both in the same file, using class is a no go.
You will try to reference a model that is not yet declared, causing
error.
That's the primary use case for model name.

2016-09-01 14:38 GMT+02:00 Javier Guerra Giraldez <javier@guerrag.com>:
> On 1 September 2016 at 11:55, James Beith <james@beith.co.uk> wrote:
>> By using a model name there are fewer imports at the top of the module and
>> fewer occurrences of circular import dependencies between Django
>> applications. What are the disadvantages to using a model name and why not
>> always use them?
>
>
> totally a wrong reason, but i like using classes instead of names
> because that way it feels more "programming" and less "configuration".
>
> a _possible_ (but not really convincing) reason would be that it makes
> it easier for tools (syntax highlight, autocompleting editors, static
> analyzers...) to detect typos.
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFkDaoQhr%2BjVo5PRS%2B5x-0j88r-4VEafVk0Pz7Cg-foUsWX7Qg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTY-_DqeQgYxoo%3D6zPhJWvGovcCe3j5yU5s-JSVABWYR3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment