Re: Trouble writing a view for a model
Rupert, Without knowing what you are aiming to accomplish, my advice might not be pertinent. However, it looks like your models could be rearranged like this: class Question(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Question) choice = models.CharField(max_length=200) votes = models.IntegerField() (Slightly modified from:http://docs.djangoproject.com/en/dev/intro/ tutorial01/) On Jul 12, 1:49 pm, rupert wrote: > For this code: > > class Title(models.Model): > title = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > > def __unicode__(self): > return self.title > > def was_published_today(self): > return self.pub_date.date() == datetime.date.today() > > class Question(models.Model): > title = models.ForeignKey(Title) > question = models.CharField(max_length=200) > choice1 = models.CharField(max_length=200) > choice2 = models.CharField(max_length=200) > choice3 = models.CharField(max_length=200) > choice4 = models.CharField(max_length=200) > choice5 = models.CharField(max_length=200) > > def __unicode__(self): > return self.question > > I'm trying to write a view where it outputs like this > > Question > > Choice 1-choice 5 in a radio button -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: way to detecting visitiors zip code
There are various tools to map a visitor's IP to their zip code: http://www.google.com/search?hl=en&q=ip+to+zip That would be where I would start with such a project... On Jul 12, 7:53 am, haibin wrote: > hi all, > > Is there a way to get the visitor's location represented as zip code > (not only in US)? I have no idea how to do this, please help. > > Thanks, > James -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Overwhelmed by File upload instructions
Soo easy... Thanks for the tips! I knew that there had to be a simple solution!! On Jul 8, 2:02 pm, Daniel Roseman wrote: > On Jul 8, 6:28 pm, Rodion Raskolnikiv wrote: > > > > > > > Good morning! > > I have been wanting to design a model (to be administered via the > > admin area) which would allow for file uploads. I have not been able > > to grasp a singular, simple approach to this. Perhaps things are > > complicated by Django's preference for serving media files under a > > different domain, but this is pretty crucial to my project and I was > > hoping that someone could point me in the right direction. > > > This post seems most > > helpful:http://groups.google.com/group/django-users/msg/02cf3d1a838e7e46 > > > but I don't want to blindly copy it and end up with a batch system! I > > am just looking to make a simple file uploader. > > > The model might look like this: > > > class UploadedFile(models.Model): > > title = models.CharField(max_length=250) > > file = forms.FileField() # I don't know if this is how to define > > it > > file_type = models.CharField(max_length=25) > > date_created = models.DateTimeField() > > > I am a huge fan of Python and Django, and I am often surprised by how > > simple and elegant the solutions are, my problem is usually that I am > > trying to do things the difficult way... > > > Any assistance would be greatly appreciated! > > The documentation for file uploads is indeed complicated, but in order > to enable file uploads in the admin you don't need to worry about any > of that. > > However you seem to be trying to declare a form field within a model. > You should of course use the models.FileField, which is fully > documented > here:http://docs.djangoproject.com/en/1.2/ref/models/fields/#filefield > Note that the only thing you *need* to do is to set a value for > upload_to. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Overwhelmed by File upload instructions
I was totally on the wrong trail! Hopefully this post can serve others who were in my dilemma: If you are looking to have a file as part of your model definition, look here: http://docs.djangoproject.com/en/dev/topics/files/ Looking in these locations did not supply what I was after: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ I don't have it entirely working just yet, but this is what I was looking to do. On Jul 8, 11:25 am, Rodion Raskolnikiv wrote: > To be more specific, here is what I have tried: > > # in models.py > from django import forms > > class UploadFileForm(forms.Form): > title = forms.CharField(max_length=50) > file = forms.FileField() > > # in admin.py > from proj.app.models import UploadFileForm > > admin.site.register(UploadFileForm) > > Which gives me the error message: > TypeError at /admin/ > 'DeclarativeFieldsMetaclass' object is not iterable > > Am I heading in the wrong direction? > > On Jul 8, 10:28 am, Rodion Raskolnikiv wrote: > > > > > Good morning! > > I have been wanting to design a model (to be administered via the > > admin area) which would allow for file uploads. I have not been able > > to grasp a singular, simple approach to this. Perhaps things are > > complicated by Django's preference for serving media files under a > > different domain, but this is pretty crucial to my project and I was > > hoping that someone could point me in the right direction. > > > This post seems most > > helpful:http://groups.google.com/group/django-users/msg/02cf3d1a838e7e46 > > > but I don't want to blindly copy it and end up with a batch system! I > > am just looking to make a simple file uploader. > > > The model might look like this: > > > class UploadedFile(models.Model): > > title = models.CharField(max_length=250) > > file = forms.FileField() # I don't know if this is how to define > > it > > file_type = models.CharField(max_length=25) > > date_created = models.DateTimeField() > > > I am a huge fan of Python and Django, and I am often surprised by how > > simple and elegant the solutions are, my problem is usually that I am > > trying to do things the difficult way... > > > Any assistance would be greatly appreciated! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Overwhelmed by File upload instructions
To be more specific, here is what I have tried: # in models.py from django import forms class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField() # in admin.py from proj.app.models import UploadFileForm admin.site.register(UploadFileForm) Which gives me the error message: TypeError at /admin/ 'DeclarativeFieldsMetaclass' object is not iterable Am I heading in the wrong direction? On Jul 8, 10:28 am, Rodion Raskolnikiv wrote: > Good morning! > I have been wanting to design a model (to be administered via the > admin area) which would allow for file uploads. I have not been able > to grasp a singular, simple approach to this. Perhaps things are > complicated by Django's preference for serving media files under a > different domain, but this is pretty crucial to my project and I was > hoping that someone could point me in the right direction. > > This post seems most > helpful:http://groups.google.com/group/django-users/msg/02cf3d1a838e7e46 > > but I don't want to blindly copy it and end up with a batch system! I > am just looking to make a simple file uploader. > > The model might look like this: > > class UploadedFile(models.Model): > title = models.CharField(max_length=250) > file = forms.FileField() # I don't know if this is how to define > it > file_type = models.CharField(max_length=25) > date_created = models.DateTimeField() > > I am a huge fan of Python and Django, and I am often surprised by how > simple and elegant the solutions are, my problem is usually that I am > trying to do things the difficult way... > > Any assistance would be greatly appreciated! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Overwhelmed by File upload instructions
Good morning! I have been wanting to design a model (to be administered via the admin area) which would allow for file uploads. I have not been able to grasp a singular, simple approach to this. Perhaps things are complicated by Django's preference for serving media files under a different domain, but this is pretty crucial to my project and I was hoping that someone could point me in the right direction. This post seems most helpful: http://groups.google.com/group/django-users/msg/02cf3d1a838e7e46 but I don't want to blindly copy it and end up with a batch system! I am just looking to make a simple file uploader. The model might look like this: class UploadedFile(models.Model): title = models.CharField(max_length=250) file = forms.FileField() # I don't know if this is how to define it file_type = models.CharField(max_length=25) date_created = models.DateTimeField() I am a huge fan of Python and Django, and I am often surprised by how simple and elegant the solutions are, my problem is usually that I am trying to do things the difficult way... Any assistance would be greatly appreciated! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Smarter URLs
Many thanks to you both! That was enough info to get things working! On Jul 7, 11:36 am, ringemup wrote: > Add a SlugField to the Page model, and populate it based on the title > (this can be done automatically either via the admin's > prepopulated_fields, or via a custom model save() method) > > class Page(models.Model): > title = models.CharField(max_length=50) > slug = models.SlugField() > > Then use a regex of the following form to pull the slug into your > view: > > (r'^(?P\d+)/(?P[\w-]+)/$', > 'project.app.views.unit_page'), > > Then in your view: > > def unit_page(request, unit_id, page_slug): > the_page = Page.objects.get(slug=PageSlug) > > Do the same for the Unit model and regex matching. Adjust as > necessary to fit your actual models. > > On Jul 7, 2:13 pm, Rodion Raskolnikiv wrote: > > > > > To clarify, I would like to take the current url form of: > > > /dept_id/page_id/ (which looks like /2/13/) > > > into a url that looks like this: > > /accounting/policy_for_travel_expenses/ (which puts the title of the > > element in place of the element ID) > > > I am getting at the elements by ID this way: > > (r'^(?P\d+)/$', 'project.app.views.unit_index'), > > (r'^(?P\d+)/(?P\d+)/$', > > 'project.app.views.unit_page'), > > > I am not sure how *[\w\d\-]+* would fit into my url configuration, I > > am still learning the very basics. > > > On Jul 7, 9:54 am, Daniel Lathrop wrote: > > > > I'm not quite clear on what you're asking, but if the issue is how to > > > write > > > a regex for slugs: The regular expression you need for slugs is > > > *[\w\d\-]+* > > > > Hope that helps. > > > > Daniel > > > --- > > > Daniel Lathrop > > > > On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv > > > wrote: > > > > > Greetings! > > > > I am trying to implement a very simple (yet elegant) solution for a > > > > university departmental website in django. In designing my urls, I > > > > desired to have them follow this pattern: > > > > university.edu/department/page_title_made_into_slug > > > > > However, I couldn't get it working or find any doc that pointed out > > > > how to do it, so I temporarily settled for: > > > > univeristy.edu/1/14 (where 1 is the department ID and 14 is the > > > > page ID) > > > > > This is how I have my URLs set up right now: > > > > (r'^$', project.app.views.index'), > > > > (r'^(?P\d+)/$', 'project.app.views.unit_page'), > > > > > I have not actually set the pages to display yet, I thought that I > > > > would ask here before I did that ... > > > > > Could anyone direct me to a solution so that I could have my URLs the > > > > way that I want them? > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups > > > > "Django users" group. > > > > To post to this group, send email to django-us...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > django-users+unsubscr...@googlegroups.com > > > groups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Smarter URLs
To clarify, I would like to take the current url form of: /dept_id/page_id/ (which looks like /2/13/) into a url that looks like this: /accounting/policy_for_travel_expenses/ (which puts the title of the element in place of the element ID) I am getting at the elements by ID this way: (r'^(?P\d+)/$', 'project.app.views.unit_index'), (r'^(?P\d+)/(?P\d+)/$', 'project.app.views.unit_page'), I am not sure how *[\w\d\-]+* would fit into my url configuration, I am still learning the very basics. On Jul 7, 9:54 am, Daniel Lathrop wrote: > I'm not quite clear on what you're asking, but if the issue is how to write > a regex for slugs: The regular expression you need for slugs is *[\w\d\-]+* > > Hope that helps. > > Daniel > ------- > Daniel Lathrop > > On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv wrote: > > > > > Greetings! > > I am trying to implement a very simple (yet elegant) solution for a > > university departmental website in django. In designing my urls, I > > desired to have them follow this pattern: > > university.edu/department/page_title_made_into_slug > > > However, I couldn't get it working or find any doc that pointed out > > how to do it, so I temporarily settled for: > > univeristy.edu/1/14 (where 1 is the department ID and 14 is the > > page ID) > > > This is how I have my URLs set up right now: > > (r'^$', project.app.views.index'), > > (r'^(?P\d+)/$', 'project.app.views.unit_page'), > > > I have not actually set the pages to display yet, I thought that I > > would ask here before I did that ... > > > Could anyone direct me to a solution so that I could have my URLs the > > way that I want them? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Smarter URLs
Greetings! I am trying to implement a very simple (yet elegant) solution for a university departmental website in django. In designing my urls, I desired to have them follow this pattern: university.edu/department/page_title_made_into_slug However, I couldn't get it working or find any doc that pointed out how to do it, so I temporarily settled for: univeristy.edu/1/14 (where 1 is the department ID and 14 is the page ID) This is how I have my URLs set up right now: (r'^$', project.app.views.index'), (r'^(?P\d+)/$', 'project.app.views.unit_page'), I have not actually set the pages to display yet, I thought that I would ask here before I did that ... Could anyone direct me to a solution so that I could have my URLs the way that I want them? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.