Re: 'NoneType' object has no attribute 'datetime' bug?
Try this: from datetime import datetime, time, date current_date = datetime.now() today = datetime.combine(date.today(), time(19,30)) Look: >>> from datetime import datetime, time, date >>> print datetime.now() 2012-07-14 14:14:17.897023 >>> print datetime.combine(date.today(),time(19,30)) 2012-07-14 19:30:00 >>> o/ 2012/7/14 dobrysmak > Hi guys, > i have run into this. > > Traceback: > File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" > in get_response > 111. response = callback(request, *callback_args, **callback_kwargs) > File > "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" > in _wrapped_view > 20. return view_func(request, *args, **kwargs) > File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" > in _wrapped_view > 91. response = view_func(request, *args, **kwargs) > File "/home/user/dev/xyz/coupon/views.py" in enter_game > 69. Coupon(coupon=coupon, player=player, credicts=credicts).save() > File "/home/user/dev/xyz/coupon/models.py" in save > 253. self.coupon.close_coupon() > File "/home/user/dev/xyz/coupon/models.py" in close_coupon > 78. current_date = datetime.datetime.now() > > Exception Type: AttributeError at /wejdz-do-gry/49/ > Exception Value: 'NoneType' object has no attribute 'datetime' > Request information: > GET: No GET data > > and the cuntion "close_coupon" looks like this > > class Coupon(models.Model): . > . > . end_date = models.DateTimeField(default=None, null=True, blank=True) > def close_coupon(self): > current_date = datetime.datetime.now() today = > datetime.datetime.combine(datetime.date.today(), datetime.time(19,30)) > . > . > end_date = current_date > > Don't know if that's a bug. Does anyone know how to deal with this issue? > Cheers! > > -- > 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/-/iH-0-noK-zkJ. > 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: Extend user model: class inheritance or OneToOneField?
Hi! I prefer using OnetoOne with a pre_delete signal to remove user from a pirncipal object instance: from django.contrib.auth.models import User from django.db.models.signals import pre_delete from django.dispatch import receiver class Customer(User): user = models.OneToOneField(User) @receiver(pre_delete, sender=Customer) def delete_user_customer(sender, instance, **kwargs): user = User.objects.filter(pk=instance.user.id) if user: user.delete() class Seller(User): user = models.OneToOneField(User) @receiver(pre_delete, sender=Seller) def delete_user_seller(sender, instance, **kwargs): user = User.objects.filter(pk=instance.user.id) if user: user.delete() 2012/7/13 sdonk > Hi, > I'm starting a new project and for the first time I need to extend the > User model. > I read the documentation and I googled a lot to try to figure out what is > the best approach but I got confused. > > What's the the best approach? > > Class inheritance: > > from django.contrib.gis.db import models > from django.contrib.auth.models import User, UserManager > > class myUser(User): > birthday = models.DateField(null=True, blank=True) > address = models.CharField(max_length=255, null=True, blank=True) > > objects = UserManager() > > Or OneToOneField (as doc suggests) > > > from django.contrib.gis.db import models > from django.contrib.auth.models import User > from django.db.models.signals import post_save > > class myUser(User): > user = models.OneToOneField(User) > birthday = models.DateField(null=True, blank=True) > address = models.CharField(max_length=255, null=True, blank=True) > > def __unicode__(self): > return u'%s' % self.user > > def create_user_profile(sender, instance, created, **kwargs): > if created: > myUser.objects.create(user=instance) > > post_save.connect(create_user_profile, sender=User) > > Thanks, > > Alex > > -- > 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/-/KtEPwiHoWbUJ. > 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: Where to delete model image?
Hi! I have this old code here. # forms.py class UploadFileForm(ModelForm): title = forms.CharField(max_length=250 ,label="Nome:") original_image = forms.ImageField(label="Imagem:") class Meta: model = Photo # models.py from django.dispatch import receiver from django.db.models.signals import pre_delete class Photo(models.Model): title = models.CharField(max_length=255) pub_date = models.DateField(auto_now = True) original_image = models.ImageField(upload_to='photos') slug_photo = AutoSlugField(populate_from=('title'), unique=True, max_length=255, overwrite=True) model = models.ForeignKey(Model, blank=True, null=True) @receiver(pre_delete, sender=Photo) def delete_image(sender, instance, **kwargs): os.remove(unicode(instance.original_image.path)) # remove the image from folder "photos" # views.py def upload_photo(request): if request.method == 'POST': model = get_object_or_404(Model, pk=request.POST.get("model")) form = UploadForm(request.POST, request.FILES) photo_exist = Photo.objects.filter(model__id = model.id) if not photo_exist: if form.is_valid(): form.save() messages.add_message(request, messages.SUCCESS, 'Image save succesfull!') return HttpResponseRedirect(reverse('detail_model', args=[model.slug])) else: return render_to_response('project/app/detail.html',locals(),context_instance=RequestContext(request)) else: if form.is_valid(): photo_exist.delete() form.save() messages.add_message(request, messages.SUCCESS, 'Image update succesfull!') return HttpResponseRedirect(reverse('detail_model', args=[model.slug])) else: photo = Photo.objects.get(model__id = model.id) # send the photo to detail page return render_to_response('project/app/detail.html',locals(),context_instance=RequestContext(request)) 2012/7/13 m.paul > Hi All, > > I have a Model with an image field and I want to be able to change the > image using a ModelForm. When changing the image, the old image should be > deleted and replaced by the new image. > > I have tried to do this in the clean method of the ModelForm like this: > > def clean(self): > cleaned_data = super(ModelForm, self).clean() > > old_profile_image = self.instance.image > if old_profile_image: > old_profile_image.delete(save=False) > return cleaned_data > > This works fine unless the file indicated by the user is not correct (for > example if its not an image), which result in the image being deleted > without any new images being saved. I would like to know where is the best > place to delete the old image? By this I mean where can I be sure that the > new image is correct before deleting the old one? I prefer to do this in my > ModelForm class if possible but doing it in the Model class would also be > acceptable. > > -- > 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/-/kB0VSrr9O1MJ. > 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: Custom Tags and Includes, invalid block !
Hi! Try {% load name_of_custom_tag %} after the extends tag in template. 2012/6/18 upmauro > Hello, sorry my english ! > > I have one question, i create one custom tag and this works fine. > > But i have a situation : > > *site.html* > * > * > {% include "header.html" %} > > Django looks the best framework for web ! > > {% include "footer.html" %} > > If, i use {% load %} in site.html, tag works, but if i {% load %} tag in > "header.html", when i try use custom tag in site.html raise Invalid block > tag. > > In short, if I load the page included a tag on it is not recognized in the > current page. > > Meant to be? > > -- > 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/-/E7i9EQSjhCoJ. > 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: no module named books found
"Do we have to create a database with that name before." Yes, you need create the database "xam" (from mysql query browser) before running syncb. 2012/6/17 Sabbineni Navneet > I have Mysqldb installed. > It still shows the same error. > > > > -- > 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 1.4 and google app engine
In GAE only using django-norel, a fork of django with no join's queryset. https://developers.google.com/appengine/articles/django-nonrel Or using in Google Cloud SQL: https://developers.google.com/appengine/docs/python/cloud-sql/django But is a paying service. 2012/6/17 Gebriel Abebe > Please I want to know the same thing? > > -- > 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/-/bU3CTr2hjmQJ. > > 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: no module named books found
The problem now is the database configuration: raise ImproperlyConfigured(" settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'xam', # Or path to database file if using sqlite3. 'USER': 'root', # Not used with sqlite3. 'PASSWORD': 'password', # Not used with sqlite3. 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '3306', # Set to empty string for default. Not used with sqlite3. } } You have the python-mysqldb package installed in your system? 2012/6/16 Satvir Toor > On Sat, Jun 16, 2012 at 4:58 PM, Sabbineni Navneet > wrote: > > > DATABASES = { > > 'default': { > > 'ENGINE': 'django.db.backends.mysql', # Add > 'postgresql_psycopg2', > > 'mysql', 'sqlite3' or 'oracle'. > > 'NAME': 'xam', # Or path to database file if > > using sqlite3. > > 'USER': 'root', # Not used with sqlite3. > > 'PASSWORD':'', # Not used with sqlite3. > what is your password here??? > > > > -- > Satvir Kaur > satveerkaur.blogspot.in > > -- > 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: no module named books found
Check the structure of project: Here I use Eclipse, and my project have this structure: myproject>myproject>app In your case: djangotest2>djangotest2>books Or: djangotest2>books And in installed_apps: INSTALLED_APPS = ( 'books', ) 2012/6/16 Sabbineni Navneet > project name is djangotest2 and app name is books > settings.py > INSTALLED_APPS = ( > 'djangotest2.books', > > > > ) > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', > 'mysql', 'sqlite3' or 'oracle'. > 'NAME': 'xam', # Or path to database file if > using sqlite3. > 'USER': 'root', # 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. > } > } > > > It shows an error :no module named books found when i use syncdb. > so anyone can please help... > > -- > 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/-/yQ3f-LdGKrEJ. > 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: Required True to Generic Relations
Solution: http://pastebin.com/011WsfzD Regards. On 15 maio, 23:43, Guevara wrote: > Hi all! > > I need a required true in Generic Relations. > Have this code: > > # Models > class Client(Person): > addresses = GenericRelation(Address) > > class Address(models.Model): > # others fields > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey('content_type', > 'object_id') > > I need create a client with an address in the form. > The DOC ignore this > question.https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#gener... > > Regards. -- 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.
Required True to Generic Relations
Hi all! I need a required true in Generic Relations. Have this code: # Models class Client(Person): addresses = GenericRelation(Address) class Address(models.Model): # others fields content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') I need create a client with an address in the form. The DOC ignore this question. https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations Regards. -- 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: Problem with a clean in inline formset
Solution: def clean(self): if any(self.errors): # Don't bother validating the formset unless each form is valid on its own return for i in range(0, self.total_form_count()): form = self.forms[i] cleaned_data = form.clean() display = cleaned_data.get('display', None) if cleaned_data['DELETE'] == False: if display.max_windows() >= display.windows: raise forms.ValidationError("The display have all windows occupied.") Put the line if cleaned_data['DELETE'] == False: to check if the inline have the attribute DELETE and if is false, to ignore deleted rows in formset that have true in this attribute. =) 2012/4/30 Guevara > Hello! > > The (if display.max_windows() >= display.windows) works fine to > prevent insert. Behaves as expected. > But is raised even when the row is REMOVED from the edit formset. =/ > > ## Models > > class Display(models.Model): >windows = models.IntegerField() > > def max_windows(self): >total = self.window_set.all().count() #window is a > intermediary class to campaign >if total: >return total > > ## Clean method in CampaignInlineFormSet > > def clean(self): >if any(self.errors): ># Don't bother validating the formset unless each form is > valid on its own >return >for i in range(0, self.total_form_count()): >form = self.forms[i] >cleaned_data = form.clean() >display = cleaned_data.get('display', None) >if display.max_windows() >= display.windows: >raise forms.ValidationError("The display have all > windows occupied.") > > This "if" can not stop me remove a row in inline formset. How can I > fix this? > Regards. > > -- > 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.
Problem with a clean in inline formset
Hello! The (if display.max_windows() >= display.windows) works fine to prevent insert. Behaves as expected. But is raised even when the row is REMOVED from the edit formset. =/ ## Models class Display(models.Model): windows = models.IntegerField() def max_windows(self): total = self.window_set.all().count() #window is a intermediary class to campaign if total: return total ## Clean method in CampaignInlineFormSet def clean(self): if any(self.errors): # Don't bother validating the formset unless each form is valid on its own return for i in range(0, self.total_form_count()): form = self.forms[i] cleaned_data = form.clean() display = cleaned_data.get('display', None) if display.max_windows() >= display.windows: raise forms.ValidationError("The display have all windows occupied.") This "if" can not stop me remove a row in inline formset. How can I fix this? Regards. -- 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: Format DateTimeField in Django
I am getting messages saying I'm a spammer. What happened to this list? People are infested with viruses? On 26 ago, 16:43, Guevara wrote: > Hello! > A date is sent from another server via POST to my app in this format > > date = datetime.now().strftime('%d/%m/%Y %H:%M:%S') > > output: 26/08/2011 16:30:03 > > And must enter the default format DateTime.Now (). > This format can save, but the date is generated on another server, > then have to store in this format: > > 2011-08-25 22:13:32.726675-03 > > I tried converting a variety of ways, with strptime and strftime, > without success. > > How do I convert this "date" to this default format in django? Postgre > store this timastamp in this format. > > Regards! -- 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.
Format DateTimeField in Django
Hello! A date is sent from another server via POST to my app in this format date = datetime.now().strftime('%d/%m/%Y %H:%M:%S') output: 26/08/2011 16:30:03 And must enter the default format DateTime.Now (). This format can save, but the date is generated on another server, then have to store in this format: 2011-08-25 22:13:32.726675-03 I tried converting a variety of ways, with strptime and strftime, without success. How do I convert this "date" to this default format in django? Postgre store this timastamp in this format. Regards! -- 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: Does django 1.3 has a ubuntu deb package released!
In Ubuntu 10.04 repository stlll 1.1 version. =/ 2011/5/31 Tobias Quinn > You can always install the debian package from: > > http://packages.debian.org/wheezy/python-django > > which seems to work fine... > > On Apr 30, 3:29 am, Korobase wrote: > > Does django 1.3 has a ubuntu deb package released ! > > I have googled but get none,Any one have done this? > > 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: django raw_id_fields patch
I need change the FK id value in raw_id to Thanks! 2011/5/25 epic2005 > who have the raw_id_fields patch url.. or some sugguest for modify > raw_id_fields pop id back in the textbox , please give me , thanks a > lot. > > -- > 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: specify Postgres encoding as unicode
Hello! Open your pdAdminIII and create a database using UTF-8. For aplication this is setting for your settings.py: DEFAULT_CHARSET = 'utf-8' FILE_CHARSET = 'utf-8' Regards! 2011/5/18 Thin Rhino > Hello, > > I am wondering if it is possible for me to specify the encoding to use for > a postgresql database in the settings.py > > Going through the django documentation I could find how I could specify it > for mysql. (http://docs.djangoproject.com/en/dev/ref/databases/) > > Tried google, but... !! > > My issue is when I try and save a unicode string into the database it is > converted to \u where X is the unicode code points. > Because of this, say a VARCHAR field I need to multiply the required length > by 4, to fit in a unicode string. Hence I need to change the > database encoding to Unicode. Since django auto creates my database, I am > looking for a way to specify the same in the settings.py file. > > Cheers > ThinRhino > > -- > 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: Change select to a form in a ForeignKey relationship
Very good, I edited here. Thank You! 2011/5/13 Shawn Milochik > On 05/13/2011 04:22 PM, Guevara wrote: > >> Thank you shaw! >> >> You're welcome. Note that there's no reason to add 'commit = True' when > saving the address -- that's the default. > > > Shawn > > -- > 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: Change select to a form in a ForeignKey relationship
Thank you shaw! It works! if form.is_valid() and formE.is_valid(): address = formE.save(commit=True) employee = form.save(commit=False) employee.address = address employee.save() ## redirect to html list Thanks! On 13 maio, 16:17, Shawn Milochik wrote: > To do that you need to add a Meta to your ModelForm and exclude the > address. Then add another ModelForm for Address and put both on the page > at the same time. > > Then, after the POST, you'll need to first save the address and then add > it to the cleaned_data of the employee form (or its self.instance) > before saving. > > Not to confuse you, but you can also save the employee first if you use > "commit = False" in the save(), then save and add the address, then save > the employee again normally. > > Shawn -- 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.
Change select to a form in a ForeignKey relationship
Hello! I need to change the Select (combobox) generated by the ForeignKey relation: I have this class: class Employee(Person): address = models.ForeignKey(Address) Django automatically generates the combobox, but I wanted to be a form to enter the address of the Employee. The address is "endereco" in the image: http://postimage.org/image/zino9gxw/ Does anyone know how can I change this? 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.
Re: Using composition in Django
Thanks for the clarification, I put in the ForeignKey in employee class and is working. Regards! 2011/4/27 Tom Evans > On Sun, Apr 17, 2011 at 9:21 PM, W Craig Trader > wrote: > > If your goal is to have an employee object that has direct access to all > of > > its related person object, and whose only new data field is a reference > to > > an address object, then you should change the Employee model to this: > > > > class Address(models.Model): > >pass > > > > class Person(models.Model): > >name = models.CharField(max_length=50) > >date_inclusion = models.DateField() > > > > class Employee(models.Model): > >person = models.OneToOneField(Person) > >address = models.ForeignKey(Address) > > > > Just to point out, this is MTI reinvented, without any of the Django > syntactic magic sprinkled on top. It is exactly equivalent to this: > > class Address(models.Model): >pass > > class Person(models.Model): >name = models.CharField(max_length=50) >date_inclusion = models.DateField() > > class Employee(Person): >address = models.ForeignKey(Address) > > """ > The second type of model inheritance supported by Django is when each > model in the hierarchy is a model all by itself. Each model > corresponds to its own database table and can be queried and created > individually. The inheritance relationship introduces links between > the child model and each of its parents (via an automatically-created > OneToOneField). > """ > > > http://docs.djangoproject.com/en/1.3/topics/db/models/#multi-table-inheritance > > Cheers > > Tom > > -- > 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: Does django 1.3 has a ubuntu deb package released!
In the repository of ubuntu 10.04.2 the version 1.1.1 is available, better download version 1.3 of the Django site and install. Is very easy. Regards! 2011/4/29 Korobase > Does django 1.3 has a ubuntu deb package released ! > I have googled but get none,Any one have done this? > 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: Need advice on ecommerce app direction
I find for download "Beginning Django E-Commerce" in webmasterresourceskit site. Look that. Regards. 2011/4/25 Shant Parseghian > Hi all, I'm aware of the choices out there for Django ecommerce apps but im > confused about which to use. I need a simple shop that will do delivery only > so no shipping needs to be calculated. I'm thinking that Satchmo will be > overkill for this. Does anyone have 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.
Re: {{ STATIC_URL }} and RequestContext()
Hello! You need create a "static" folder in your project and inside in this folder you create a "css" folder. I use this configuration and works. settings.py import os.path STATIC_ROOT = '' # URL prefix for static files. STATIC_URL = '/static/' ADMIN_MEDIA_PREFIX = '/static/admin/' TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), 'templates'), ) And call a css for example, in base.html in this way: Regards. 2011/4/25 Joakim Hove > Hello, > > I have just started using the {{ STATIC_URL }} template tag to insert > proper url's to static resources in my templates. To use this tag I > need to create the context for rendering as RequestContext() instance, > which takes the request as a parameter for the initialisation. > > In my code I have several methods attached to models which create a > suitable context for rendering that model instance in a specfied way: > > class MyModel( models.Model ): > > > >def create_xxx_context( self , **kwargs): > > >def create_yyy_context( self, ,**kwargs): > > > (Maybe that is a horrific design in the first place ???). > > > Anyway - the methods create_???_context() do not have natural access > to the request object (and I am reluctant to pass that argument on) - > so I was wondering if I could achieve exactly the same by just > "manually" adding the context variable STATIC_URL like: > > from django.conf import settings > > > def view(request, args): >context = . >context["STATIC_URL"] = settings.STATIC_URL >return render_to_response( template , context ) > > Or is there more magic to the {{ STATIC_URL }} tag when it comes as a > RequestContext()? > > > Joakim > > -- > 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.
Need a OneToOne form inside another form
Hello! I have a OneToOne relationship between employee and address, and I need that form of address appears in the form of employee. I saw that Django creates a ComboBox address and load all the addresses of the batabase, what is wrong. I can not use inline because the OneToOne is in employee class and not in address. How can I change this and have a form instead of a combobox? Regards! -- 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: How to register EmployeeAdmin using atributes in Person class
I still having a little problem using OneToOne relationship and Edit form. The forms are created with combobox and get all address in database, i need the address of the specific Employee only. Anybody know fix this problem? Thanks! 2011/4/23 Guevara > I got put in the form of employee the form of Houses using > StackedInline: > > > class HouseInline(admin.StackedInline): >model = House >max_num = 1 > > class EmployeeAdmin(admin.ModelAdmin): >search_fields = ['person__name','person__cpf'] >list_display = ("name","cpf","date_born","date_inclusion") >ordering = ["-name"] > list_filter = ("date_inclusion",) >list_per_page = 10 > inlines = [HouseInline] > > admin.site.register(Employee, EmployeeAdmin) > > Now I need collapse the forms of Houses in edit form of Employee, if I > register mora than 2 houses, I have two forms of Houses in edit form > employee. =/ > And the address combobox still showing all address register in > database, i need show olnly adress of employee or adress of the house. > > Thanks. > > > > > On 23 abr, 12:46, Guevara wrote: > > Thank you Ramiro! > > > > Now i have the atributes Person in form Employee. =) > > > > I added the attribute address and house in Employee class: > > > > models.py > > > > class Employee(Person): > > person = models.OneToOneField(Person, parent_link=True) > > # Relationship OneToOne with Address > > address = models.OneToOneField(Address) > > # Relationship with Houses > > house = models.ForeignKey(Houses) > > > > def __unicode__(self): > > if self.person: > > return "%s %s (%s)" % (self.name, self.tel, self.address) > > else: > > return "%s (%s)" % (self.name, self.address) > > > > admin.py > > > > from django.contrib import admin > > from imobiliaria.employee.models import Employee > > admin.site.register(Employee) > > > > But when registering a new Employee, the form show in the combobox > > others addresses and other houses of other entries, you know how I can > > fix? > > > > Thanks!! > > > > On 23 abr, 00:22, Ramiro Morales wrote: > > > > > > > > > > > > > > > > > On Fri, Apr 22, 2011 at 11:55 PM, Guevara > wrote: > > > > [...] > > > > > > class Person(models.Model): > > > >name = models.CharField(max_length=50) > > > >date_inclusion = models.DateField() > > > > > > class Employee(models.Model): > > > >person = models.OneToOneField(Pessoa) > > > > > > I reed this dochttp:// > docs.djangoproject.com/en/dev/ref/contrib/admin/ > > > > but could not find this information. > > > > > Try with > > > > > class Employee(Person): > > > person = models.OneToOneField(Person, parent_link=True) > > > > > or simply with > > > > > class Employee(Person): > > > pass > > > > > It you don't want/need control of the name of the 1to1 relationship > > > between Employee and Person. > > > > > Also, see > > > > > > http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield > .. > > > > > -- > > > Ramiro Morales > > -- > 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: How to register EmployeeAdmin using atributes in Person class
I got put in the form of employee the form of Houses using StackedInline: class HouseInline(admin.StackedInline): model = House max_num = 1 class EmployeeAdmin(admin.ModelAdmin): search_fields = ['person__name','person__cpf'] list_display = ("name","cpf","date_born","date_inclusion") ordering = ["-name"] list_filter = ("date_inclusion",) list_per_page = 10 inlines = [HouseInline] admin.site.register(Employee, EmployeeAdmin) Now I need collapse the forms of Houses in edit form of Employee, if I register mora than 2 houses, I have two forms of Houses in edit form employee. =/ And the address combobox still showing all address register in database, i need show olnly adress of employee or adress of the house. Thanks. On 23 abr, 12:46, Guevara wrote: > Thank you Ramiro! > > Now i have the atributes Person in form Employee. =) > > I added the attribute address and house in Employee class: > > models.py > > class Employee(Person): > person = models.OneToOneField(Person, parent_link=True) > # Relationship OneToOne with Address > address = models.OneToOneField(Address) > # Relationship with Houses > house = models.ForeignKey(Houses) > > def __unicode__(self): > if self.person: > return "%s %s (%s)" % (self.name, self.tel, self.address) > else: > return "%s (%s)" % (self.name, self.address) > > admin.py > > from django.contrib import admin > from imobiliaria.employee.models import Employee > admin.site.register(Employee) > > But when registering a new Employee, the form show in the combobox > others addresses and other houses of other entries, you know how I can > fix? > > Thanks!! > > On 23 abr, 00:22, Ramiro Morales wrote: > > > > > > > > > On Fri, Apr 22, 2011 at 11:55 PM, Guevara wrote: > > > [...] > > > > class Person(models.Model): > > > name = models.CharField(max_length=50) > > > date_inclusion = models.DateField() > > > > class Employee(models.Model): > > > person = models.OneToOneField(Pessoa) > > > > I reed this dochttp://docs.djangoproject.com/en/dev/ref/contrib/admin/ > > > but could not find this information. > > > Try with > > > class Employee(Person): > > person = models.OneToOneField(Person, parent_link=True) > > > or simply with > > > class Employee(Person): > > pass > > > It you don't want/need control of the name of the 1to1 relationship > > between Employee and Person. > > > Also, see > > >http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield.. > > > -- > > Ramiro Morales -- 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: How to register EmployeeAdmin using atributes in Person class
Thank you Ramiro! Now i have the atributes Person in form Employee. =) I added the attribute address and house in Employee class: models.py class Employee(Person): person = models.OneToOneField(Person, parent_link=True) # Relationship OneToOne with Address address = models.OneToOneField(Address) # Relationship with Houses house = models.ForeignKey(Houses) def __unicode__(self): if self.person: return "%s %s (%s)" % (self.name, self.tel, self.address) else: return "%s (%s)" % (self.name, self.address) admin.py from django.contrib import admin from imobiliaria.employee.models import Employee admin.site.register(Employee) But when registering a new Employee, the form show in the combobox others addresses and other houses of other entries, you know how I can fix? Thanks!! On 23 abr, 00:22, Ramiro Morales wrote: > On Fri, Apr 22, 2011 at 11:55 PM, Guevara wrote: > > [...] > > > class Person(models.Model): > > name = models.CharField(max_length=50) > > date_inclusion = models.DateField() > > > class Employee(models.Model): > > person = models.OneToOneField(Pessoa) > > > I reed this dochttp://docs.djangoproject.com/en/dev/ref/contrib/admin/ > > but could not find this information. > > Try with > > class Employee(Person): > person = models.OneToOneField(Person, parent_link=True) > > or simply with > > class Employee(Person): > pass > > It you don't want/need control of the name of the 1to1 relationship > between Employee and Person. > > Also, see > > http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefieldhttp://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-in...http://docs.djangoproject.com/en/dev/topics/db/models/#specifying-the... > > -- > Ramiro Morales -- 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.
How to register EmployeeAdmin using atributes in Person class
Hello! I need register EmployeeAdmin using atributes in Person class: My admin.py: class EmployeeAdmin(admin.ModelAdmin): list_display = ("name","date_inclusion") ordering = ["-name"] search_fields = ("name",) list_filter = ("date_inclusion",) list_per_page = 10 admin.site.register(Employee,EmployeeAdmin) I got this exception: Exception Value is: EmployeeAdmin.list_display[0], 'name' is not a callable or an attribute of 'EmployeeAdmin' or found in the model 'Employee'. My models.py: class Person(models.Model): name = models.CharField(max_length=50) date_inclusion = models.DateField() class Employee(models.Model): person = models.OneToOneField(Pessoa) I reed this doc http://docs.djangoproject.com/en/dev/ref/contrib/admin/ but could not find this information. 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.
Re: The import staticfiles_urlpatterns is not working in django 1.3
Hello Brian! This right, in fact that word "import" I inadvertently pasted, but the import does not work. from django.contrib.staticfiles.urls import staticfiles_urlpatterns The problem was that when doing the import, it does not appear available by pressing ctrl + backspace in Eclipse, that is, the import does not exist. In fact, not need it, and even configure the urls.py. With the configuration that I have informed the css work Thanks! 2011/4/21 Brian Neal > On Apr 21, 12:48 pm, Guevara wrote: > > Hello! > > My project is failing to import the staticfiles_urlpatterns, using > > Eclipse Helios: > > > > urls.py > > > > import from django.contrib.staticfiles.urls staticfiles_urlpatterns > > > > In django 1.3 I already have: > > > > INSTALLED_APPS = ( > > 'django.contrib.staticfiles' > > ) > > > > In the folder: > > / usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles > > > > Why do not you think the staticfiles_urlpatterns? > > > > Thanks! > > Please post your code and the exact error. For one thing, your import > statement isn't valid Python. It should be: > > from django.contrib.staticfiles.urls import staticfiles_urlpatterns > > Best, > BN > > -- > 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: The import staticfiles_urlpatterns is not working in django 1.3
The problem was the documentation, the manual of utilization says one thing, but the Contrib documentation says another, I follow contrib doc: This is the configuration that worked: settings.py STATIC_ROOT = '' STATIC_URL = '/static/' STATICFILES_DIRS = ( "/home/guevara/workspace/imobiliaria/static", ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ) And call CSS in base.html: Thanks! On 21 abr, 14:48, Guevara wrote: > Hello! > My project is failing to import the staticfiles_urlpatterns, using > Eclipse Helios: > > urls.py > > import from django.contrib.staticfiles.urls staticfiles_urlpatterns > > In django 1.3 I already have: > > INSTALLED_APPS = ( > 'django.contrib.staticfiles' > ) > > In the folder: > / usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles > > Why do not you think the staticfiles_urlpatterns? > > 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.
The import staticfiles_urlpatterns is not working in django 1.3
Hello! My project is failing to import the staticfiles_urlpatterns, using Eclipse Helios: urls.py import from django.contrib.staticfiles.urls staticfiles_urlpatterns In django 1.3 I already have: INSTALLED_APPS = ( 'django.contrib.staticfiles' ) In the folder: / usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles Why do not you think the staticfiles_urlpatterns? 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.
Re: admin login fails
Or you can delete database and execute again syncdb. The aplication ask again the password, warning for capslock. =) 2011/4/19 pfc > I'm new to Django and am following the tutorials, specifically: > http://docs.djangoproject.com/en/dev/intro/tutorial02/ > I followed the instructions on adding admin to the INSTALLED_APPS, I > also added it to the urls, did syncdb and created the superuser. When > trying to login with the superuser(username test, password test) I > then get the message "Please enter a correct username and password. > Note that both fields are case-sensitive." > I decided to create a second superuser and restarted the test server, > and still have the same issue. > > A few days ago I had no problems getting this to work, but now even > when trying to create a new project I still get the same error. > Any ideas as to what I'm missing or what might be happening? > > Thanks in advance for any help :-) > > -- > 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: Import error No module named urls to url login_in in html page
Thank you Subhranath! I do not know what happened, but I created a new project and put the same configuration and is now working. I think it was a problem with the framework. I made the correction on this line: AUTH_PROFILE_MODULE = 'imobiliaria.login' <-- login app Thanks! On 19 abr, 06:49, Subhranath Chunder wrote: > Hi, > > The problems seems to be with the way you are using the view prefixes in the > 'patterns' function in your urls.py > Refer > to:http://docs.djangoproject.com/en/dev/topics/http/urls/#the-view-prefix > > You have used 'view' string twice. > > Thanks, > Subhranath Chunder. > > > > > > > > On Tue, Apr 19, 2011 at 5:11 AM, Guevara wrote: > > Hello!! > > > I am getting the following error on my index.html page: > > > Exception Type: TemplateSyntaxError > > Exception Value: > > > Caught ImportError while rendering: No module named urls > > > In this line: > > > Login > > > My urls.py: > > > (r'^imobiliaria/', include('auth.urls')), > > > In my auth app, i have this: > > > urlpatterns = patterns('auth.views', > > url(r'^$', views.index, name="index"), <-- this is index page > > url(r'^accounts/login/$', views.login_in, name="login_in"), <-- > > this is login page > > url(r'^logout/$', views.logout_view, name="logout_view"), > > url(r'^register/$', views.register, name="register"), > > url(r'^home/$', views.home, name="home"), > > ) > > > My view to render index.html is: > > > def index(request): > > return render_to_response('imobiliaria/auth/index.html') > > > In my settings.py i have this: > > > AUTH_PROFILE_MODULE = 'imobiliaria.imobiliaria' > > LOGIN_URL = '/imobiliaria/accounts/login/' > > > INSTALLED_APPS = ( > > 'imobiliaria.auth', > > ) > > > ROOT_URLCONF = 'imobiliaria.urls' > > > Anyone know where the problem might be? > > 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.
Import error No module named urls to url login_in in html page
Hello!! I am getting the following error on my index.html page: Exception Type: TemplateSyntaxError Exception Value: Caught ImportError while rendering: No module named urls In this line: Login My urls.py: (r'^imobiliaria/', include('auth.urls')), In my auth app, i have this: urlpatterns = patterns('auth.views', url(r'^$', views.index, name="index"), <-- this is index page url(r'^accounts/login/$', views.login_in, name="login_in"), <-- this is login page url(r'^logout/$', views.logout_view, name="logout_view"), url(r'^register/$', views.register, name="register"), url(r'^home/$', views.home, name="home"), ) My view to render index.html is: def index(request): return render_to_response('imobiliaria/auth/index.html') In my settings.py i have this: AUTH_PROFILE_MODULE = 'imobiliaria.imobiliaria' LOGIN_URL = '/imobiliaria/accounts/login/' INSTALLED_APPS = ( 'imobiliaria.auth', ) ROOT_URLCONF = 'imobiliaria.urls' Anyone know where the problem might be? 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.
Re: Using composition in Django
Hello Craig! Thanks for the reply! Actually I want to use a form that will save the Employee data and would be sent to the Employee class, and this class has relationship with the Person and Address, the data would automatically be persisted. Follow the instructions you suggested and they match what the manual says: http://docs.djangoproject.com/en/dev/topics/db/models/#relationships I did classes like this: class Employee (models.Model): person = models.OneToOneField(Person) # only one person related address = models.OneToOneField(Address) # only one address for employee sectors= models.ForeignKey(Sectors) # one or various sectors for the employee This is the SQL: CREATE TABLE "employee_employee" ( "id" serial NOT NULL PRIMARY KEY, "person_id" integer NOT NULL UNIQUE, "address_id" integer NOT NULL UNIQUE, "sectors_id" integer NOT NULL ) Thanks for help! On 17 abr, 17:21, W Craig Trader wrote: > On 04/16/2011 04:35 PM, Guevara wrote: > > > > > > > > > > > Hello! > > I have two class, Person and employee, i need make a composition for > > this (Prefer composition over inheritance): > > > class Person(models.Model): > > name = models.CharField(max_length=50) > > date_inclusion = models.DateField() > > # others fields > > > class Employee(models.Model): > > person = models.OneToOneField(Person, primary_key=True) > > address = models.OneToOneField(Address, primary_key=True) > > > The SQL generate is: > > > BEGIN; > > CREATE TABLE "person_person" ( > > "id" serial NOT NULL PRIMARY KEY, > > "name" varchar(50) NOT NULL, > > "date_inclusion" date NOT NULL, > > ) > > ; > > CREATE TABLE "employee_employee" ( > > "person_id" integer NOT NULL PRIMARY KEY, > > "address_id" integer NOT NULL PRIMARY KEY, > > ) > > ; > > > This is correct? Should generate the id of the employee? > > Proxy models could be used for this case? > > > Thanks! > > It's correct in that Django has done exactly what you've told it you want, > but I doubt that what > you've told it is what you REALLY want. > > If your goal is to have an employee object that has direct access to all of > its related person > object, and whose only new data field is a reference to an address object, > then you should change > the Employee model to this: > > class Address(models.Model): > pass > > class Person(models.Model): > name = models.CharField(max_length=50) > date_inclusion = models.DateField() > > class Employee(models.Model): > person = models.OneToOneField(Person) > address = models.ForeignKey(Address) > > This will change the generated employee table to something like this (for > SQLite3): > > CREATE TABLE "foo_address" ( > "id" integer NOT NULL PRIMARY KEY > ) > ; > CREATE TABLE "foo_person" ( > "id" integer NOT NULL PRIMARY KEY, > "name" varchar(50) NOT NULL, > "date_inclusion" date NOT NULL > ) > ; > CREATE TABLE "foo_employee" ( > "id" integer NOT NULL PRIMARY KEY, > "person_id" integer NOT NULL UNIQUE REFERENCES "foo_person" ("id"), > "address_id" integer NOT NULL REFERENCES "foo_address" ("id") > ) > ; > CREATE INDEX "foo_employee_b213c1e9" ON "foo_employee" ("address_id"); > > With these models, every Employee object will have an equivalent Person > object (though you may have Persons without corresponding Employees). You > can then use these models as follows: > > (InteractiveConsole)>>> from foo.models import * > >>> from datetime import datetime > >>> now = datetime.now() > >>> p = Person( name='Tom', date_inclusion=now ) > >>> p.save() > >>> a = Address() > >>> a.save() > >>> e = Employee( person=p, address=a ) > >>> e.save() > >>> e.person.name > > 'Tom' > > - Craig - -- 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: Using composition in Django
Thanks for the replies! if I leave the class person like this: class Employee(models.Model): person = models.OneToOneField(Person) This is SQL generated: CREATE TABLE "person_person" ( "id" serial NOT NULL PRIMARY KEY, "name" varchar(50) NOT NULL, ) ; CREATE TABLE "employee_employee" ( "person_id" integer NOT NULL UNIQUE, "address_id" integer NOT NULL PRIMARY KEY, ) And when I need to get the employee data, I call Person or Employee? I can call the Employee who is using the person_id? Thanks!! On 16 abr, 20:06, Ian Clelland wrote: > On Sat, Apr 16, 2011 at 1:35 PM, Guevara wrote: > > Hello! > > I have two class, Person and employee, i need make a composition for > > this (Prefer composition over inheritance): > > > class Person(models.Model): > > name = models.CharField(max_length=50) > > date_inclusion = models.DateField() > > # others fields > > > class Employee(models.Model): > > person = models.OneToOneField(Person, primary_key=True) > > address = models.OneToOneField(Address, primary_key=True) > > > The SQL generate is: > > > BEGIN; > > CREATE TABLE "person_person" ( > > "id" serial NOT NULL PRIMARY KEY, > > "name" varchar(50) NOT NULL, > > "date_inclusion" date NOT NULL, > > ) > > ; > > CREATE TABLE "employee_employee" ( > > "person_id" integer NOT NULL PRIMARY KEY, > > "address_id" integer NOT NULL PRIMARY KEY, > > ) > > ; > > > This is correct? Should generate the id of the employee? > > I don't think it's correct -- a database table shouldn't have two distinct > primary keys. It's the "primary_key=True" part of your Employee model fields > that is doing this, and is also stopping an "id" field from being > automatically generated. > > If you write Employee like this: > > class Employee(models.Model): > person = models.OneToOneField(Person) > address = models.OneToOneField(Address) > > Then it will generate SQL like this: > > CREATE TABLE "employee_employee" ( > "id" serial NOT NULL PRIMARY KEY, > "person_id" integer NOT NULL, > "address_id" integer NOT NULL > ) > ; > > which is probably closer to what you're expecting. > > -- > Regards, > Ian Clelland > -- 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.
Using composition in Django
Hello! I have two class, Person and employee, i need make a composition for this (Prefer composition over inheritance): class Person(models.Model): name = models.CharField(max_length=50) date_inclusion = models.DateField() # others fields class Employee(models.Model): person = models.OneToOneField(Person, primary_key=True) address = models.OneToOneField(Address, primary_key=True) The SQL generate is: BEGIN; CREATE TABLE "person_person" ( "id" serial NOT NULL PRIMARY KEY, "name" varchar(50) NOT NULL, "date_inclusion" date NOT NULL, ) ; CREATE TABLE "employee_employee" ( "person_id" integer NOT NULL PRIMARY KEY, "address_id" integer NOT NULL PRIMARY KEY, ) ; This is correct? Should generate the id of the employee? Proxy models could be used for this case? 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.
Re: populating a field based on selection of foreign key
Hello! I think you need something like this in your admin.py: class SystemAdmin(admin.ModelAdmin): list_display = ("generation", "system", "cog_E") ordering = ["-cog_E"] search_fields = ("system") list_filter = ("generation") list_per_page = 10 admin.site.register(System, SystemAdmin) Try this. =) 2011/4/9 Aref > I am working on a database project and I am facing a little challenge. > Here it is. > > I have three tables defined as below: > > class Generation(models.Model): >generation = models.CharField(max_length = 25) > >def __unicode__(self): >return self.generation > > class CogE(models.Model): >first_name = models.CharField(max_length=30) >last_name = models.CharField(max_length=30) >office_phone = models.CharField(max_length=15, blank=True) >mobile_phone = models.CharField(max_length=15, blank=True) >email = models.EmailField(blank=True) > >def __unicode__(self): >return u'%s %s' % (self.first_name, self.last_name) > > class System(models.Model): >system = models.CharField(max_length=30) >cog_E = models.ForeignKey(CogE) >project = models.ForeignKey(Project) >generation = models.ForeignKey(Generation) > >def __unicode__(self): >return self.system > > > class Board(models.Model): >board = models.CharField(max_length=30) >sch_number = models.CharField(max_length=20, blank = True) >PWA_number = models.CharField(max_length=20, blank = True) >PWB_number = models.CharField(max_length=20, blank = True) >system = models.ForeignKey(System) >cog_E = models.ForeignKey(CogE) >generation = models.ForeignKey(Generation) > > In the admin view I would like to the board generation field to be > populated based on the system entry (since generation is also a field > in the system table). Is this possible to do in django? Is the schema > correct (I know this is not really a django issue)? Any help is > 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-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: My success messages are not returned
Solved! The problem is the "RequestContext", all views need this parameters on return function, like this: If I have this function "edit": def edit(request, object_id): #code here return HttpResponseRedirect('/vagas/list') My function "list" need this in return: return render_to_response('vagas/list.html', {'lista':lista}, context_instance=RequestContext(request)) The key is -> context_instance=RequestContext(request) in all return's. Thanks! =) On 9 abr, 16:38, Guevara wrote: > Hello! > I need return a "message success" to my list view, but the message not > appears on html page. > > This is my function edit: > > from django.shortcuts import redirect > > def edit(request, object_id): > if request.method == 'POST': > e = Emprego.objects.get(pk=object_id) > form = EditForm(request.POST, instance=e) > if form.is_valid(): > form.save() > messages.success(request, 'Vaga alterada com sucesso!.') > <-- here is the message > return redirect('/vagas/lista') <-- here is the redirect > else: > vaga = Emprego.objects.get(pk=object_id) > form = EditForm(instance=vaga) > return render_to_response('vagas/edit.html', {'form': form}) > > I put configurations on settings.py: > > MIDDLEWARE_CLASSES > 'django.contrib.messages.middleware.MessageMiddleware', > > TEMPLATE_CONTEXT_PROCESSORS > 'django.contrib.messages.context_processors.messages', > > INSTALLED_APPS > 'django.contrib.messages', > > And put this code in html page to view the message success: > > {% if messages %} > > {% for message in messages %} > {{ message > }} > > {% endfor %} > > {% endif %} > > Anyone know why not working? No message is displayed. =/ > > 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.
My success messages are not returned
Hello! I need return a "message success" to my list view, but the message not appears on html page. This is my function edit: from django.shortcuts import redirect def edit(request, object_id): if request.method == 'POST': e = Emprego.objects.get(pk=object_id) form = EditForm(request.POST, instance=e) if form.is_valid(): form.save() messages.success(request, 'Vaga alterada com sucesso!.') <-- here is the message return redirect('/vagas/lista') <-- here is the redirect else: vaga = Emprego.objects.get(pk=object_id) form = EditForm(instance=vaga) return render_to_response('vagas/edit.html', {'form': form}) I put configurations on settings.py: MIDDLEWARE_CLASSES 'django.contrib.messages.middleware.MessageMiddleware', TEMPLATE_CONTEXT_PROCESSORS 'django.contrib.messages.context_processors.messages', INSTALLED_APPS 'django.contrib.messages', And put this code in html page to view the message success: {% if messages %} {% for message in messages %} {{ message }} {% endfor %} {% endif %} Anyone know why not working? No message is displayed. =/ 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.