Hi Vikrant,

On 15/08/2018 15.11, Vikrant Gupta wrote:
Sure. May I know what’s the reason not to use in model code?

I'm far from being an expert in Django, so I don't know the details, but I'm sure Django does quite a lot of "magic" when you write a class that inherits from models.Model which is most likely the cause of the error you see.

Apart from the actual issues you're having, I think it's a lot cleaner design to stick to defining model classes in models.py (or wherever you declare your models) and avoid writing any code there that is evaluated at import time.

In general I think it's better to avoid having code being evaluated at import time unless you have a very good reason for that (and there are tons of those, but as a rule of thumb).

So How can I develop my project?


I assume you're trying to debug your models or just taking things step by step, which is a very good way to approach things IMO.

Jason suggested you could you use the shell, which is definitely one good option for testing things out.

I would probably write a very simple view, move the code you posted there and access that from your browser. The view might not really return anything, or even fail, but assuming you're going to use your models in that view anyway, it's a good way to see (in your console output) that something works before you start passing model instances to render templates etc.

You could also start writing unittests for your models, views etc. which is something I highly recommend doing no matter what, but that's probably out of scope for now :-)

Just my 2 cents.

Kind regards,

Kasper Laudrup

--
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 [email protected].
To post to this group, send email to [email protected].
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/8ecf7080-1b2e-aefc-7c2a-94952e2bf5cc%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to