Re: Looking for Django IDE
Try to use vim with plugins for django. 02.04.2012 1:48 пользователь "Mark Phillips" написал: > What IDE do you use/recommend for developing django web sites? Or, if not > an IDE, what editor/setup is most useful? I am developing on Linux version > 3.1.0-1-amd64 (Debian 3.1.8-2). I would rather use something open source. I > use eclipse for developing android/java projects. Since I am using django > in conjunction with an android project, I don't want to use the plugin for > eclipse. Switching between python and java perspectives is a little > annoying, so I thought I would find a separate ide for my django work and > just alt-tab between them. > > I have tried gedit, but I cannot get the django plugin to work. I am > looking at ninja, but there does not appear to be a django plugin. > > Thanks, > > Mark > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: Tutorial issue with admin
You can add list_display = ['question', ] on your PollAdmin class. 2012/4/11 Romain Gaches : > you just have to define a __unicode__ method [1] in your model > > [1] > https://docs.djangoproject.com/en/1.4/ref/models/instances/#django.db.models.Model.__unicode__ > > > Le 11/04/2012 06:54, oneroler a écrit : > > I'm working on the tutorial and ran across an issue that I can't figure > out. In the admin site in "Select Polls to Change" instead of displaying > the question associated with the poll (e.g. "What's up") it displays "poll > object" for all polls. I've attached a screen shot of the issue. Below is > my code. Any help would be appreciated. > > mysite/polls.models.py > from django.db import models > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(max_length=200) > votes = models.IntegerField() > > mysite/polls/admin.py > from polls.models import Poll, Choice > from django.contrib import admin > > class PollAdmin(admin.ModelAdmin): > fieldsets = [ > (None, {'fields': ['question']}), > ('Date information', {'fields': ['pub_date'], 'classes': > ['collapse']}), > ] > > admin.site.register(Poll, PollAdmin) > admin.site.register(Choice) > > mysite/settings.py > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', > 'mysql', 'sqlite3' or 'oracle'. > 'NAME': > '/Users/Sam/dev/django/mysite/mysite1.sqlite', # Or > path to database file if using sqlite3. > 'USER': '', # Not used with sqlite3. > 'PASSWORD': '', # Not used with sqlite3. > 'HOST': '', # Set to empty string for > localhost. Not used with sqlite3. > 'PORT': '', # Set to empty string for default. > Not used with sqlite3. > } > } > > INSTALLED_APPS = ( > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.staticfiles', > # Uncomment the next line to enable the admin: > 'django.contrib.admin', > # Uncomment the next line to enable admin documentation: > # 'django.contrib.admindocs', > 'polls', > ) > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/r6d6l_4q6fUJ. > To post to this group, send email to django-users@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. > > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: Sessions living through HttpResponseRedirect
Set request.session.modified = True 2012/4/24 sspross : > Hi Joshua > > What was your solution here? It looks like I'm having the same kind of > problem like you: > > http://stackoverflow.com/questions/10293467/losing-session-after-httpresponseredirect > > Thx! > > Regards, > Silvan > > On Wednesday, April 1, 2009 4:47:17 AM UTC+2, Joshua K wrote: >> >> Howdy Folks, >> >> How do I get a session to live through a HttpResponseRedirect? For >> example: >> >> form = clientFormCreate(request.POST) >> if form.is_valid(): >> newClient = form.save() >> request.sesson['current_client'] = str(newClient.pk) >> return HttpResponseRedirect('/clients/') >> >> I was under the impression that I had to re-create a context from the >> modified request object, then render the context - but you can't >> render a context with HttpResponseRedirect. >> >> Thanks! >> -Josh > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/3DrUy8ckwDYJ. > To post to this group, send email to django-users@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. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re:: Trouble with query syntax in Django view
You can get teacher and parents objects from student instance. student.teacher and student.teachers.all() 01.05.2012 11:46 пользователь "LJ" написал: > I have a Student model that stores information about a student, > including the student's teacher. > The teacher's information is stored in the Employee model that > inherits from the Person Model. > I am having trouble figuring out how to query the teacher, when a > student id is passed as an ajax argument to the view function. > I have no trouble returning the data about the parents and the > student, but my filter for querying the teacher info is incorrect. > Does anyone have any ideas how I can query for the teacher information > based on the models below? > > #models.py > class Student(Person): >grade = models.ForeignKey('schools.Grade') >school = models.ManyToManyField('schools.School', blank=True, > null=True, related_name="school") >parents = models.ManyToManyField('parents.Parent', blank=True, > null=True) >teacher = models.ForeignKey(Employee, blank=True, null=True, > related_name='teacher') > > class Employee(Person): >''' Employee model inherit Person Model''' >role=models.ForeignKey(EmployeeType, blank=True, null=True) >user=models.ForeignKey(User) >schools = > models.ManyToManyField(School,blank=True,null=True) > > # views.py > def get_required_meeting_participants(request, template): >try: >id=request.GET['id'] >except: >id=None > >parents = Parent.objects.filter(student=id) >student = Student.objects.filter(pk=id) >teacher = Employee.objects.filter(pk=student.teacher_id) #this > line is incorrect...help, please? > >data = { >'parents': parents, >'student': student, >'teacher': teacher, >} > >return > render_to_response(template,data, >context_instance=RequestContext(request)) > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: Trouble with query syntax in Django view
First of all. Student.objects.filter(pk=id) returns QuerySet not instance of Student. If you want get current student use get_object_or_404()(https://docs.djangoproject.com/en/1.4/topics/http/shortcuts/#get-object-or-404) or Student.objects.get(pk=id). Teacher and parents can bee retrived via Student instance: teacher = student.teacher parents = student.parents.all() 2012/5/1 LJ : > I have a Student model that stores information about a student, > including the student's teacher. > The teacher's information is stored in the Employee model that > inherits from the Person Model. > I am having trouble figuring out how to query the teacher, when a > student id is passed as an ajax argument to the view function. > I have no trouble returning the data about the parents and the > student, but my filter for querying the teacher info is incorrect. > Does anyone have any ideas how I can query for the teacher information > based on the models below? > > #models.py > class Student(Person): > grade = models.ForeignKey('schools.Grade') > school = models.ManyToManyField('schools.School', blank=True, > null=True, related_name="school") > parents = models.ManyToManyField('parents.Parent', blank=True, > null=True) > teacher = models.ForeignKey(Employee, blank=True, null=True, > related_name='teacher') > > class Employee(Person): > ''' Employee model inherit Person Model''' > role=models.ForeignKey(EmployeeType, blank=True, null=True) > user=models.ForeignKey(User) > schools = > models.ManyToManyField(School,blank=True,null=True) > > # views.py > def get_required_meeting_participants(request, template): > try: > id=request.GET['id'] > except: > id=None > > parents = Parent.objects.filter(student=id) > student = Student.objects.filter(pk=id) > teacher = Employee.objects.filter(pk=student.teacher_id) #this > line is incorrect...help, please? > > data = { > 'parents': parents, > 'student': student, > 'teacher': teacher, > } > > return > render_to_response(template,data, > context_instance=RequestContext(request)) > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: HELP with unicode!!!!!
Write at first line on your py file: # -*- coding: utf-8 -*- 2012/5/1 dizzydoc : > Hi , > > i have lost a lot of time looking for a solution. > > My problem is, while i a reading csv in python using > > csv_file = open(path_file, "rb") > reader = csv.reader(csv_file) > > whenever i perform any operation on the string returned in each cell i > get this error > > *** UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' > in position 34: ordinal not in range(128) > > i tried decoding the value as > > val.decode('utf-8') > > ...this helped to reduce a few encodings but gets stuck for > the encoding "\xa0" > Please HELP! > > Thanks > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: Modify __unicode__
Use in __unicode__ method strftime def __unicode__(self): return "%s %s" % (self.name, self.date_created.strftime("%A %d %B") Look at strftime: http://docs.python.org/library/datetime.html?highlight=strftime#datetime.date.strftime 2012/5/2 Nikhil Verma : > Hi All > > In models.py my table structure is :- > > class ABC(models.Model): > name = models.CharField(max_length=80,blank=True,null=True) > date_created = models.DateTimeField(blank=True,null=True) > > def __unicode__(self): > return "%s %s" % (self.name, self.date_created) > > > Let say my first entry is :- > name = django > date_created = 2012-05-02 # it will look like this datetime.datetime(2012, > 5, 2, 15, 42, 24) > > I want to modify this ABC(__unicode__ method) object in such a way that > whenever i call this object from forms > like this :- > > forms.py > > efg = forms.ModelChoiceField(queryset= ABC.objects.all()) > > The dropdown created above should have values like this:- > > 1) django Wednesday PM 2 May # Modify dateTimeField which retuen day of > week AM or PM and then day and name of month > 2) django1 Wednesday PM 2 May > . > . > . > . > and so on .. > > How can i modify the __unicode__ method to achieve this ? > > If there is other ways to achieve this that involves changing the table > structure i won't mind. > > Thanks > > > > -- > Regards > Nikhil Verma > +91-958-273-3156 > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: ajax call says: "NetworkError: 500 INTERNAL SERVER ERROR - http://127.0.0.1:8000/ajax/"
Your view should return an HttpResponse Object. Your view prints 'test' and returns NoneType Object. Yours view should be like this: from django.http import HttpResponse def ajax(request): return HttpResponse('test', mimetype="text/plain") 2012/5/5 doniyor : > hi there, > i have a small problem. i googled a lot, but couldnot find anything which > helps me. > > i have $.ajax call and before that i have included the js file where i have > that csrf-protection code from djangodocs. > > here is my ajax call: http://dpaste.com/hold/743156/ > > but once i click on the event, i get this error: "NetworkError: 500 INTERNAL > SERVER ERROR - http://127.0.0.1:8000/ajax/";. > my urls.py has: url(r'^ajax/', 'home.views.ajax'), > > and my ajax function is simply: > > def ajax(request): > print 'test' > > i dont have any clues why this is happening. can someone please help me? > > many many thanks > > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/1Y1E6RZOc7wJ. > To post to this group, send email to django-users@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. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Different urls.py file for different apps
you could include urls of app into your_app/urls.py urlpatterns = patterns('', (r'your_app/', include('your_apps.urls')) (r'your_app2/', include('your_apps2.urls')) ) 2012/5/22 siddharth56660 : > Hi, > I am developing an ERP system which is vast and covers many modules. > After developing each module i create another app for second module > by > " django-admin.py startapp myapp2 " > This is perfectly working fine. > But my urls.py is growing very fast and has crossed more than 5000 > lines with lot more to come. > > Is there any other way in which i can make different urls.py as per my > apps. > I tried googling around but i dint find any way to give multiple apps > in setting.py file in ROOT_URLCONF entry. > > Please help me around. > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: Django ModelForm user best practices
I think that the first method is the most usefull. On second method some experience users can override hidden data. And it's a bad idea to override __init__ and save method in my humble opinion/ 2012/5/31 RM : > Say there's a model: > > class Notification(models.Model): > user = models.ForeignKey(User) > board = models.ForeignKey(Board) > post = models.ForeignKey(Post) > name = models.CharField() > > class Meta: > unique_together = ('user', 'name', 'post', 'board') > #i know this is funny.. just for purpose of this post > > In every post there's a form that you can fill with "name" value. > This way the logged in user gets notification on every post update. > > What is the best way to save the "user", "board", "post" data ? > > 1. Saving in the views directly (CBV): > > class NotificationModelForm(forms.ModelForm): > class Meta: > model = Notification > fields = ["name"] > > class CreateNotificationView(CreateView): > model = Notification > form_class = NotificationForm > def form_valid(self, form): > data = form.save(commit=False) > data.user = self.request.user > data.board = ... > data.post = ... > data.save() > > * if you have model validators (unique_together for user... this won't no > longer work when submitting the form) > > 2. Displaying all the fields in the form, with some fields hidden > > class NotificationModelForm(forms.ModelForm): > class Meta: > fields = ["user", "board", "post", "name"] > > def __init__(self, *args, **kwargs): > super(NotificationModelForm, self).__init__(*args, **kwargs) > for field in ["user", "board", "post"]: > forms.field['field'].widget = forms.HiddenInput() > #I know this can be done other ways too > > Now we need to prepopulate fields with initial data for these fields > > class CreateNotificationView(CreateView): > model = Notification > form_class = NotificationModelForm > > def get_initial(self): > initial = super(CreateNotificationView, self).get_initial() > initial['user'] = self.request.user > initial['board'] = ... > initial['post'] = > return initial > > If the same field pattern (user, board, post) is used in more forms/views... > I can also create a MixinView > > class CommonUserFormMixin(object): > > def get_form(self, form_class): > form = super(CommonUserFormMixin, self).get_form(form_class) > for field in ['user', 'board', 'post']: > form.fields[field].widget = forms.HiddenInput() > > Then: > > class NotifcationModelForm(forms.ModelForm): > class Meta: > model = Notification > fields = ["user", "board", "post", "name"] > > class CreateNotificationView(CommonUserFormMixin, CreateView): > form_class = NotificationModelForm > model = Notification > > * in 2 above scenarios we get model validators working. > 3. Sending values to the form directly and overriding the form.save() method > > class CreateNotificationView(CreateView): > model = Notification > form_class = NotificationModelForm > > def get_form_kwargs(**kwargs): > kwargs = super(CreateNotificationView, > self).get_form_kwargs(**kwargs) > kwargs['user'] = self.request.user > kwargs['board'] = ... > kwargs['post'] = ... > return kwargs > > class NotificationModelForm(forms.ModelForm): > class Meta: > model = Notification > fields = ["name"] > > def __init__(self, *args, **kwargs): > self.user = kwargs.pop('user') > self.post = kwargs.pop('post') > self.board = kwargs.pop('board') > > super(NotificationModelForm, self).__init__(*args, **kwargs) > > def save(*args, **kwargs): > n = super(NotificationModelForm, self).save(commit=False) > n.user = self.user > n.post = self.post > n.board = self.board > n.save() > return n > > > I'm sure there are more ways to achive the same result. > What are your thoughts on that ? > > When should I 'hide' (by using HiddenInput() widget) ModelForm fields? when > should I save them directly > in view? > > Does it all depend on needs or maybe there are some "best" standards ? > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/xn6xNGKJ2CEJ. > To post to this group, send email to django-users@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. -- 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 grou
Re: Django ModelForm user best practices
For example on second method i can change post, board id's via html, and write to board where i can be banned. I think we shoudn't override standart methods if we con don't override them(this about third method) P.S. sorry for my terrible english. 2012/5/31 Kurtis Mullins : >> On second method some experience users can >> override hidden data > > For the second method, you'd just use -- class Meta: fields = > ('board', 'post', 'name') to prohbit anyone from trying to override > the 'user', if that's what you're talking about. > >> And it's a bad idea to >> override __init__ and save method in my humble opinion/ > > What better purpose for the save() method than to save? :) I'm not > sure why it's a bad idea to override __init__, though. Feel free to > elaborate. I'm always open for new information! > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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: decorating an include in urls.py
Try to use this library https://github.com/jeffkistler/django-decorator-include 2012/7/6 Gelonida N : > I'd like to decorate all views in an include. > > Let's take for example: > > urlpatterns = patterns('', > url(r'^decorated_admin/', include(admin.site.urls)), > ) > > > Is there any way to decorate all views in admin.site.urls > > I was looking for a syntax similiar to: > > urlpatterns = patterns('', > url(r'^webfw/admin/', include_and_decorate(admin.site.urls, > mydecorator)), > ) > > > > > One use case would be for example to add authentification or specific > logging to an entire list of views. > > > Thanks in advance for any suggestions. > > -- > 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 > django-users+unsubscr...@googlegroups.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-users@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.