Re: Specifying model relationship as string vs concrete model?

2019-04-06 Thread Mike Dewhirst
Using the class means you have to import it first. I have stuck to the string 
version since encountering circular import errors some time ago. Django is 
smart enough to get it right so I don't even think about it.

YMMV

Mike

Connected by Motorola

Mohit Solanki  wrote:

>Since Django provides two ways of specifying model relationship, 
>
>
>models.ForeignKey('User') vs models.ForeignKey(User)
>
>
>Which one is more preferred and recommended? Is there any upside or downside 
>of choosing one over the other?  In Django documentation, all the example are 
>of the second form but I have seen many people specifying the relationship as 
>a string. Can Someone please elaborate more on this?
>
>
>Regards,
>
>
>Mohit
>
>-- 
>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+unsubscr...@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/06988f5c-9ad0-47b1-9216-5f689abb1720%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@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/rbtrryas0cl949dqomv4rvbs.1554611799912%40email.android.com.
For more options, visit https://groups.google.com/d/optout.


Specifying model relationship as string vs concrete model?

2019-04-06 Thread Mohit Solanki
Since Django provides two ways of specifying model relationship, 

models.ForeignKey('User') vs models.ForeignKey(User)

Which one is more preferred and recommended? Is there any upside or 
downside of choosing one over the other?  In Django documentation, all the 
example are of the second form but I have seen many people specifying the 
relationship as a string. Can Someone please elaborate more on this?

Regards,

Mohit

-- 
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+unsubscr...@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/06988f5c-9ad0-47b1-9216-5f689abb1720%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: In the browser it looks ugly, why?

2019-04-06 Thread Alex Heyden
Short answer, it's giving you exactly what you asked for: the query set
inside  tags.
What you probably want is to loop through the ingredients and place them
inside  tags. Something like:

{% for ingredient in object.ingredientes.all %}
{{ ingredient.cantidad }} {{ ingredient.nombre }}
{% endfor %}


On Sat, Apr 6, 2019 at 4:28 PM Barkalez XX  wrote:

> Why does this happen to me?
>
>
>
>  https://pasteboard.co/I8VU79E.png
>
>
>
>  html:https://dpaste.de/AVti
>
>
>  views.py:https://dpaste.de/44Jz
>
>
>  models.py: https://dpaste.de/Dfwy
>
>
>
> I want to list all the ingredients in that recipe and make it look
> beautiful.
>
> --
> 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+unsubscr...@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/07ff0403-914f-46ae-a418-6c42a9de8ac2%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CA%2Bv0ZYUMiGD0ZWXwWXOih%2BbGuWoX8nSDAKkC5V75scuDcs2JhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


In the browser it looks ugly, why?

2019-04-06 Thread Barkalez XX
Why does this happen to me?



 https://pasteboard.co/I8VU79E.png



 html:https://dpaste.de/AVti  


 views.py:https://dpaste.de/44Jz   


 models.py: https://dpaste.de/Dfwy



I want to list all the ingredients in that recipe and make it look 
beautiful.

-- 
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+unsubscr...@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/07ff0403-914f-46ae-a418-6c42a9de8ac2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


TypeError unsupported operand type(s) for *: 'NoneType' and 'int'

2019-04-06 Thread omar ahmed
models.py
class Club(models.Model):
league_names = models.ForeignKey(League, on_delete= models.CASCADE, 
related_name='club')
name = models.CharField(max_length=100)
logo = models.ImageField(upload_to='media/core', max_length=255, null=True, 
blank=True)
won = models.IntegerField()
draw = models.IntegerField()
lost = models.IntegerField()
goal_for = models.IntegerField()
goal_against = models.IntegerField()
club_position = models.IntegerField()

def CalcPoints(self):
return self.won*3 + self.draw


admin.py

class ClubAdmin(admin.ModelAdmin):
list_display = ['league_names', 'name', 'logo', 'won', 'draw', 'lost', 
'total_points', 'goal_for', 'goal_against', 'goal_diff']
readonly_fields = ('total_points', 'goal_diff',)

admin.site.register(Club, ClubAdmin)

total_points = property(CalcPoints)

def GoalDiff(self):
return self.goal_for - self.goal_against

goal_diff = property(GoalDiff)


def __str__(self):
return self.name

-- 
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+unsubscr...@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/8ccf9b0f-da36-470e-9489-a4edd264943a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: What is the proper workflow before first migration?

2019-04-06 Thread 'dtdave' via Django users
The error you are getting  is because the CustomUser is not included in 
your settings.py
Because I use a separte user model my settings.py has this line in it:
AUTH_USER_MODEL = 'users.CustomUser'
I would recommend that you have your Custom User as a separate user model.
For  good tutorials on user models have a look at these links:
https://wsvincent.com/django-tips-custom-user-model/
https://wsvincent.com/django-login-with-email-not-username/
https://wsvincent.com/django-custom-user-model-tutorial/

Django All-Auth is a good app for customising your user models:
https://www.intenct.nl/projects/django-allauth/
Hope this helps!


On Friday, 5 April 2019 15:58:19 UTC+1, silverst...@gmail.com wrote:
>
> Hello, I've been trying to make a social media site and know nothing about 
> django (i've been teaching myself using the documentation and tutorials) 
> I've had to redo the site three times and now have to do a fourth because 
> (even though I got AUTH_USER_MODEL in, all the forms ect. ect. before first 
> migration) for some reason it is saying that "Manager is unavailable; 
> auth.User has been swapped for public_posts.CustomUser". I have not been 
> able to find a decent description on exactly how work flow NEEDS to be 
> done. Obviously create user models and set AUTH_USER_MODEL before first 
> migration but what about the Manager? I made my CustomUserManager at the 
> same time as everything else.
>
> I tried to use django-registration, then found out they upgraded to 
> django_registration, couldn't find ANY documentation on it until almost a 
> week afterwards. So now my code is partially a bunch of tutorials and 
> partially old (possibly deprecated) code, is there somewhere that all of 
> the new stuff and how to transfer to the new stuff posted? This seems to be 
> the hardest part about Django, for me anyway. I've tried get_user_model 
> where user comes up to no avail.  I have three apps, admin_posts, 
> public_posts and accounts (get ready to smirk cuz this was stupid of me) I 
> have all my CustomUser stuff in public_posts and have everything required 
> by django_registration in accounts. I'm positive that was a huge fail on my 
> part but Where SHOULD all of the user stuff go?? I have no been able to 
> find anything about that anywhere everything only says ' 
> appname.CustomUser' (example) leading me to believe that it doesn't matter 
> where you put them. but since django_registration has its own requirements 
> and user dealings, will using django_registration and CustomUsers cancel 
> each other out/mess up each others managers?
>
> Everything I have done has only been in my project(s) and not in the root 
> dir. Also, if anyo contributors to django read this, thank you for making 
> such a freaking amazing framework, I mean this thing is just a pure beauty 
> so thank you!!! Y'all be some geniuses! I hope to be good enough to 
> contribute.
>
> Thank you for making it to the end and thank you for any responses.
> P.S I only post as a last resort, I've spent HOURS researching this to no 
> avail, not even a tease of an answer...I'm only saying this so you know I 
> do indeed do the research required and don't want others to do  my work for 
> me but MAN I cannot find anything. Also, if any Django contributors read 
> this, Thank you for making such an amazing framework!!
>

-- 
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+unsubscr...@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/5aedce0e-870b-48ea-89cb-98e7b022d66d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Regarding password and email field

2019-04-06 Thread Soumen Khatua
How I can display please enter the same password. if both password is
different in django inbuilt auth forms.

-- 
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+unsubscr...@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/CAPUw6WZk%2BWKiPHhH-35Huc0iE8Gg6HPBxJyvFcv_v8EXVkok4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.