django-models

Django Model ForeignKey 2

I dont understand how I can "import"(I dont know the right terminology, so please dont crucify me on this) a Foreignkey from 1 model class to a another: e.g. class1 (models.Model): variable1 = models.CharField() variable2 = models.CharField() class2 (models.Model): variable3 = models.CharField() variable4 = class1.vari...

Django Queryset to List conversion => Data loss?

I'm trying to populate a list based on partiular members, but it doesn't seem to be going to plan. user = request.user members = [] userprofile = user.get_profile() if user.is_superuser or user.is_staff: if userprofile.countries.count() == 0: members = Member.objects.all() elif userprofile.countr...

Django ForeignKey which does not require referential integrity?

I'd like to set up a ForeignKey field in a django model which points to another table some of the time. But I want it to be okay to insert an id into this field which refers to an entry in the other table which might not be there. So if the row exists in the other table, I'd like to get all the benefits of the ForeignKey relationship. ...

accent letter's or special (ñ) in verbose_name or help_text ?

Hi guys, how ill use accent's letter's or special characters like ñ in verbose_name or help_text? Thanks ...

Django many-to-many problem in admin

I am essentially creating a blog application in django as a way of learning the ropes and boosting my skill level in django. I basically have a many-to-many relationship that I am having problems with in the admin site. I have two main types, Article and ArticleTag. Many Articles can belong to many ArticleTags, and the relationship shoul...

Django - dreaded 'iteration over non-sequence'

Hi I'm looking to populate a list of members, based on where their club comes from. This is my code: members = [] if userprofile.countries.count() > 0: for c in userprofile.countries.all(): clubs = Club.objects.filter(location__country = c) for club in clubs: members_list = Member.objects.get_membe...

Django admin action with file upload - process file content and put it in database

Hi, I want to add some functionality in admin that allows me to upload file and the process it. I already have a model that I can edit trough the admin, but I want to be able to "upload" multiple items with this file processing. How can I achieve this in the admin? ...

Does deleting a Django Model object with a File field delete the storage used for the file?

Does deleting a Django Model object with a File field delete the storage used for the file? Does it delete the file on disk? ...

Django - Search related fields

My models: class Contact(models.Model): first_name = models.CharField(_("First name"), max_length=30, ) last_name = models.CharField(_("Last name"), max_length=30, ) email = models.EmailField(_("Email"), blank=True, max_length=75) class PhoneNumber(models.Model): contact = models.ForeignKey(Contact) phone = models.C...

Django: pkey is none after saving

Hi, I have a strange behaviour on my Django/PostgreSQL system. After saving a model object the primary key is none although it's an AutoField and the id is correctly saved in the database. The following script passage returns None for the id: a = SomModelClass() a.someattribute = 'xyz' a.save() a.someattribute >>> 'xyz' a.id >>> None...

django model choice option as a multi select box

Assuming that I have such model COLORS= ( ('R', 'Red'), ('B', 'Yellow'), ('G', 'White'), ) class Car(models.Model): name = models.CharField(max_length=20) color= models.CharField(max_length=1, choices=COLORS) It displays as a selectbox in the admin panel however I would like my admin-user to multi select those colo...

Get a list of items from a model

I have this class class Category(models.Model): title = models.CharField(max_length=60) created = models.DateTimeField() def __unicode__(self): return self.title class Meta: verbose_name_plural = "Categories" I can access its items using Category.objects.all() from my views.py. I want to access these items inside my ...

HowTo Install the Django emailauth App into a New Project

Hello, I'm a Django newbie and am interesting in understanding how to install the EmailAuth app into my new project: http://github.com/redvasily/django-emailauth Seems like Django apps are meant to be plug in play so I must be missing something.... Here's what I tried. I created a new project copied the emailauth directory over Updat...

how to get a certain number of elements from the database django

I have a simply class class BlogPost(models.Model): title = models.CharField(max_length=150) ... timestamp = models.DateTimeField() How do I get the last five items from the database. I tried to do like this: posts = BlogPost.objects.<any code> Excuse me for bad English ...

django permalink error

Hi all! I have a page with some years. I want to click over the year, for instance 2000, to see all the information. What I have in urls is this: url(r'^browse/time/(\d{4})/$', 'TBDBsite.tb.views.data_time', name="yr"), In models: @permalink def get_absolute_url(self): return('year', [str(self.date.year)]) And in the tem...

Foreignkeyfield - verbose name not shown in form

Hi there, my verbose_name of a foreignkeyfield isn't printed in my forms. (I create the modelforms via modelformset_factory model class MOrders(models.Model): amount = models.IntegerField('Bestellmenge', null=True, blank=True) order_date = models.DateField('Bestelldatum') id = models.AutoField(primary_key=True) m_produ...

Accessing related models in Django?

Please forgive me if this question is ridiculous. I'm relatively new to programming and Django. Following the typical Publisher, Author, Book example.... Publisher to Author (One to Many) Author to Book (One to Many) I'm trying to get Django to give me a list of books published by all the authors under a single publisher. Two ways I...

django annotation and filtering

Hi, Hopefully this result set is explanatory enough: title text total_score already_voted ------------- ------------ ----------- ------------- BP Oil spi... Recently i... 5 0 J-Lo back ... Celebrity ... 7 1 Don't Stop... If there w... 9 0 Austr...

Django: How to define a dynamic initial value on a ForeignKey Model Field

How can one define a dynamic initial value on a foreign key field? With the code: from django.db import models from django.conf import settings from django.contrib.sites.models import Site class Example(models.Model): site = models.ForeignKey(Site, initial=settings.SITE_ID) I've the following error: site = models.ForeignKey(Sit...

Get class name of django model

Hi there, I have a django model: class Book(models.Model): [..] and I want to have the model name as string: 'Book'. When I try to get it this way: Book.__class__.__name__ it returns 'ModelBase'. Any idea? ...