having trouble with django models

2017-12-16 Thread Mukul Agrawal
Hello, I am newbie to django. I was trying my hand on models. When i used 
the below code in models.py, "timestamp" and "updated" are not able visible 
on admin site. Is something wrong with the code? 

'''
from django.db import models

# Create your models here.
class RestaurantLocation(models.Model):
name = models.CharField(max_length=120)
location = models.CharField(max_length=120, null=True, 
blank=True)
category = models.CharField(max_length=120, null=True, 
blank=True)
timestamp= 
models.DateTimeField(auto_now=False,auto_now_add=True)
updated  = models.DateTimeField(auto_now=True, 
auto_now_add=False)

'''

-- 
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/a80a81c1-fade-42a0-b8f5-20638541a5bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


confusion in models in django

2017-12-18 Thread Mukul Agrawal
I am a bit confused that is it necessary to write the name of the app in 
the INSTALLED_APPS in settings.py. Because whether I write it or not, I am 
able to successfully run my project. Then what is the difference between 
the two method.

-- 
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/f869b60a-76cf-4a95-b2f0-9c854f79101b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


what is the use of get_queryset

2018-01-25 Thread Mukul Agrawal
I have two snap of code below.  I want to know that in the first one I used 
template_name='restaurants/restaurants_list.html' which is obvious if I 
want to use a template but in the second one I have not specified the 
template name even then it shows the correct web page.How? 




class RestaurantListView(ListView):
template_name='restaurants/restaurants_list.html'
def get_queryset(self):
slug=self.kwargs.get("slug")
if slug:
queryset=RestaurantLocation.objects.filter(
Q(category__iexact=slug)|
Q(category__icontains=slug)
)
else:
queryset=RestaurantLocation.objects.all()
return queryset 

##

class RestaurantListView(ListView):
def get_queryset(self):
return RestaurantLocation.objects.all(owner=self.request.user)




-- 
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/c29ef43a-ff1e-4008-a2c9-099bf226d5df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When to use get_user_model()

2018-02-18 Thread Mukul Agrawal
The answer on this link can also help you in why and when to use
get_user_model().
https://stackoverflow.com/questions/24629705/django-using-get-user-model-vs-settings-auth-user-model


On Feb 18, 2018 4:11 AM, "tango ward"  wrote:


Hi,

I am playing around with user registration. I came across a code where the
get_user_model() was assigned to a model in Meta class inside a form. I was
just wondering, what is the benefit of using the get_user_model() as Model
in a form instead of importing a class from models.py then use that class
as model of the form and when should I use it?

models.py
class RegUser(User):

def __str__(self):
return self.username

forms.py

class UserCreateForm(UserCreationForm):

class Meta:
fields = ('username', 'password1', 'password2')
model = get_user_model()


Thanks,
Jarvis

-- 
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/CAA6wQL%2Bq1kQ7ukjtE3gV64iu9y2SXdgojZX
BF3R46BCuTN0xoA%40mail.gmail.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/CACRd7haky8%2BY7%2BNDHNFV3EbiSxBU4B65CJUSF7v3mXb3%3DP8D%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.