Django Template for_loop by user
Hi, I'm trying to get a for loop to display data by user. So for example I have the following that will display all 'courses' running in my project: {% if course %} There are Courses The current courses we are running are: {{course|join:", "}} {% else %} There are currently no courses running. {% endif %} But what I'd ideally like if for the user who is logged in to see just the courses he/she is on. Can any of you suggest how I might do that? Thanks for your help - always much appreciated! Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Get first_name from User Model in to my Model
Hi, I am having a problem getting data from the user model in to my model (below). I can get the usernames easy enough using "user = models.ForeignKey(User)", but how then do I get the first_name & last_name in to my model from the user model? Any ideas appreciated, Thanks, Ed class Student(models.Model): user = models.ForeignKey(User) first_name = models.CharField(maxlength=40) age = models.IntegerField() location = models.CharField(maxlength=40) def __str__(self): return self.first_name class Admin: list_display = ('user', 'age', 'location',) list_filter = ('user', 'location',) ordering = ('-user',) search_fields = ('user',) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Connect users in models.py to admin site users
hang on, I may have found the answer here: http://groups.google.com/group/django-users/browse_thread/thread/8933164dfc790200/f7ef4498f1391aac?lnk=gst=link+class+to+user#f7ef4498f1391aac On Apr 20, 8:29 pm, chiefmoamba <[EMAIL PROTECTED]> wrote: > Hello, > > I have a model in models.py as shown below: > > class Tutor(models.Model): > first_name = models.CharField(maxlength=40) > last_name = models.CharField(maxlength=40, core=True) > etc... > etc... > > It simply captures fname and lname and adds it to my database. It > works. > > However, the 'Tutor' should also be an user on my site, as found in > the Auth section of the admin page. Clearly, I don't ant to replicate > the information, that'd be silly, right? > > What I'd like to do is two fold: > > 1) Add a field to Auth Users section to show whether a user is a > Tutor or a Student > 2) Use a ForeignKey (I guess thats best right) to add the names of the > user to my Tutor Model above. > > Can anyone help me with this, please? I don't even know how to find > the Admin Auth Users Model at the moment and try as I might, I can > find nothing on the web to help me solve the issue. Any help is > appreciated! > > Thanks, > > Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Connect users in models.py to admin site users
Hello, I have a model in models.py as shown below: class Tutor(models.Model): first_name = models.CharField(maxlength=40) last_name = models.CharField(maxlength=40, core=True) etc... etc... It simply captures fname and lname and adds it to my database. It works. However, the 'Tutor' should also be an user on my site, as found in the Auth section of the admin page. Clearly, I don't ant to replicate the information, that'd be silly, right? What I'd like to do is two fold: 1) Add a field to Auth Users section to show whether a user is a Tutor or a Student 2) Use a ForeignKey (I guess thats best right) to add the names of the user to my Tutor Model above. Can anyone help me with this, please? I don't even know how to find the Admin Auth Users Model at the moment and try as I might, I can find nothing on the web to help me solve the issue. Any help is appreciated! Thanks, Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin page doesn't show calendar popup
Hi, I had the same problem earlier - 0.96 on Leopard. How do you switch to trunk? Thanks, Ed On Apr 20, 4:53 pm, sinker <[EMAIL PROTECTED]> wrote: > Switching to trunk WORKED. Thank you so much! > > On Apr 19, 7:42 am, Polat Tuzla <[EMAIL PROTECTED]> wrote: > > > I got the same problem with the version 96.1 on Mac. > > Then switched to trunk and everything went OK. > > Unfortunately can't tell you why this happened, as I did not bother to > > investigate the problem further. > > Just switch to using trunk if that suits you, and you will have the > > calendar pop ups. > > > On Mar 30, 8:39 am, Hoolio <[EMAIL PROTECTED]> wrote: > > > > I just installed Django 96.1 on my Mac. When I follow the tutorial > > > and get to the Admin page, the calendar pop ups don't show up. Is > > > there a problem with the install. I'm using Leopard. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: DateTimeField calendar not showing
Yes - sorry. In the admin. Thanks. Ed On Apr 20, 1:59 pm, Juanjo Conti <[EMAIL PROTECTED]> wrote: > chiefmoamba escribió: > > > Hi All, > > > For some reason my DateTimeField is not showing a calendar next to the > > 'DateTime' box in my view. My code from models.py is below. Can anyone > > offer me any suggestions? I am using 0.96. > > You mean in the admin or in any other place? > > Juanjo > -- > mi blog:http://www.juanjoconti.com.ar --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
DateTimeField calendar not showing
Hi All, For some reason my DateTimeField is not showing a calendar next to the 'DateTime' box in my view. My code from models.py is below. Can anyone offer me any suggestions? I am using 0.96. Thanks, Ed from django.db import models class Course(models.Model): course = models.CharField(maxlength=100, core=True) start_date = models.DateTimeField() end_date = models.DateTimeField() def __str__(self): return self.course class Admin: list_display = ('course', 'start_date', 'end_date', ) list_filter = ('course',) ordering = ('-course',) search_fields = ('course',) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Displaying user names on all pages
Hi there, Thanks for this - it worked :-) For any who may read this and need a little extra help, the html page contained: {% if user.is_authenticated %} Welcome, {{ user.username }}. Thanks for logging in. {% else %} Welcome, new user. Please log in. {% endif %} And views.py also needed to have from django.template import RequestContext ...in it Thanks again for your help. Ed On Apr 19, 7:43 pm, Raisins <[EMAIL PROTECTED]> wrote: > Add context_instance=RequestContext(request) to your > render_to_response for your views > > render_to_response('mainpage.html', {'stuff' : stuf }, > context_instance=RequestContext(request)) > > On Apr 19, 1:36 pm, chiefmoamba <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I am hoping this will be a very simple question for many of you. > > > I have built simple Django login function. When I log in, my log in > > page will say "Welcome, username" etc. It works beautifully. > > > However, on subsequent pages, eg /nextpage/ even though I have the > > same code in the page, the username doesn't display: > > > {% if request.user.is_authenticated %} > > {{ user.username }} is logged in. > > {% else %} > > You are not logged in. > > {% endif %} > > > I don't understand why it works on the login page only. > > > It may be worth mentioning that I have a login_required decorator on > > the page so I don't really need the if/else above, I am aware of that > > but I am being desperate! > > > Any thoughts? > > > Thanks, > > > Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Displaying user names on all pages
Hello, I am hoping this will be a very simple question for many of you. I have built simple Django login function. When I log in, my log in page will say "Welcome, username" etc. It works beautifully. However, on subsequent pages, eg /nextpage/ even though I have the same code in the page, the username doesn't display: {% if request.user.is_authenticated %} {{ user.username }} is logged in. {% else %} You are not logged in. {% endif %} I don't understand why it works on the login page only. It may be worth mentioning that I have a login_required decorator on the page so I don't really need the if/else above, I am aware of that but I am being desperate! Any thoughts? Thanks, Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Trying to display a list
I'm sure this will be very easy for most of you... I am trying to display a list. in views.py, I have: from mysite.books.models import Book from django.http import HttpResponse def book_list(request): book = Book.objects.all().order_by('title') return render_to_response('books/book_list.html', {'book': book}) in models.py, I have: class Book(models.Model): title = models.CharField(maxlength=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField() num_pages = models.IntegerField(blank=True, null=True) def __str__(self): return self.title In my HTML is: {% if "book_list" %} There are books {% endif %} The title of your books: {{ book }} Now the thing is, when it renders in the browser, I get something that looks like this: There are books The title of your books: [, ] If I view source, I get this: There are books The title of your books: [, ] So clearly the data is there - I just can't see it. Can anyone help shed light on this, please? I have been at it all day and I am am about to crack! ;-) (Incidentally, this relates to some code at the start of Chapter 5, djangobook) Thanks, Ed --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---