django-models

Django, How authenticate user with first name and last name?

i want to authenticate users using firstname and lastname This is the code i am using user = auth.authenticate(first_name=firstname,last_name=lastname,password=password) it keep coming up with NoneType: None i have checked the firstname and lastname plus password seen to be correct? what i am doing wrong? thanks ...

Django database caching

I have a Django form that uses an integer field to lookup a model object by its primary key. The form has a save() method that uses the model object referred to by the integer field. The model's manager's get() method is called twice, once in the clean method and once in the save() method: class MyForm(forms.Form): id_a = fields.I...

Django QuerySet filter method returns multiple entries for one record

Trying to retrieve blogs (see model description below) that contain entries satisfying some criteria: Blog.objects.filter(entries__title__contains='entry') The results is: [<Blog: blog1>, <Blog: blog1>] The same blog object is retrieved twice because of JOIN performed to filter objects on related model. What is the right syntax for...

Sort list of items in Django

Hi Guys, I have a Django view called change_priority. I'm posting a request to this view with a commas separated list of values which is basically the order of the items in my model. The data looks like this: 1,4,11,31,2,4,7 I have a model called Items which has two values - id and priority. Upon getting this post request, how can I ...

Change user email in Django without using django-profiles

Hi guys, In my Django application I would like the user to be able to change the email address. I've seen solution of StackOverflow pointing people to django-profiles. Unfortunately I don't want to use a full fledged profile module to accomplish a tiny feat of changing the users email. Has anyone seen this implemented anywhere. The emai...

Django model translation : store translations in database or use gettext ?

I'm in a django website's I18N process. I've selected two potentially good django-apps : django-modeltranslation wich modifies the db schema to store translations django-dbgettext wich inspect db content to create .po files and uses gettext From your point of view, what are the pros and cons of those two techniques ? ...

Can a django model have embed classes?

Hi, I want to have a django model like this: class Model(models.Model): string = models.CharField() class ContactDetails: phone = models.IntegerField() Is this possible? I've tried googling but it doesn't seem to answer my question This would mean i'd have while accesssing: Model().ContactDetails.phone working like that :) Jo...

Help with Django Model relationship & admin screen

My first time with Django and StackOverflow so could do with a little help. A Platform has many Categories and a Category can belong to many Platforms. A product belongs to one Platform and one or more of that Platforms Categories. So this is what I have so far for my Models: class Category(models.Model): name = models.CharField(...

Django - how to make ImageField/FileField optional?

class Product(models.Model): ... image = models.ImageField(upload_to = generate_filename, blank = True) When I use ImageField (blank=True) and do not select image into admin form, exception occures. In django code you can see this: class FieldFile(File): .... def _require_file(self): if not self: ...

How do I store values of arbitrary type in a single Django model?

Hi Say I have the unknown number of questions. For example: Is the sky blue [y/n] What date were your born on [date] What is pi [3.14] What is a large integ [100] Now each of these questions poses a different but very type specific answer (boolean, date, float, int). Natively django can happily deal with these in a model. clas...

In django changing the file name of uploading file.

Hi Is it possible to change the file name of the uploading file in the django? I searched, but couldn't find any answer. My requirement is whenever a file is uploaded its file name should be changed in the following format. format = userid + transaction_uuid + file_extension Thank yo very much... ...

Showing user ratings for django object list

I have a template which is just a simple list of objects, and I would like to show the current user's rating for each object next to that object. Here are the relevant models: class Problem(models.Model): question = models.TextField() answer = models.TextField() topic = models.ForeignKey(Topic) class Attempt(models.Model): ...

How do I use Django signals with an abstract model?

I have an abstract model that keeps an on-disk cache. When I delete the model, I need it to delete the cache. I want this to happen for every derived model as well. If I connect the signal specifying the abstract model, this does not propagate to the derived models: pre_delete.connect(clear_cache, sender=MyAbstractModel, weak=False) ...

Complex derived attributes in Django models

What I want to do is implement submission scoring for a site with users voting on the content, much like in e.g. reddit (see the 'hot' function in http://code.reddit.com/browser/sql/functions.sql). Edit: Ultimately I want to be able to retrieve an arbitrarily filtered list of arbitrary length of submissions ranked according to their sc...

How to do custom display and auto-select in django admin multi-select field?

I'm new to django, so please feel free to tell me if I'm doing this incorrectly. I am trying to create a django ordering system. My order model: class Order(models.Model): ordered_by = models.ForeignKey(User, limit_choices_to = {'groups__name': "Managers", 'is_active': 1}) in my admin ANY user can enter an order, but ordered_by mu...

how to save django object using dictionary?

is there a way that I can save the model by using dictionary for e.g. this is working fine, p1 = Poll.objects.get(pk=1) p1.name = 'poll2' p1.descirption = 'poll2 description' p1.save() but what if I have dictionary like { 'name': 'poll2', 'description: 'poll2 description' } is there a simple way to save the such dictionary direct...

django models objects filter

Hello All, I have a model 'Test' ,in which i have 2 foreignkey models.py class Test(models.Model): id =models.Autofield(primary_key=True) name=models.ForeignKey(model2) login=models.ForeignKey(model1) status=models.CharField(max_length=200) class model1(models.Model): id=models.CharField(primary_key=True) . ...

Django App for Image heavy Magazine Publishing?

I'm about to begin work on a Django project for an image heavy non-profit "community arts" magazine. The magazine is published monthly with about 6-8 articles that include with 4-10 images. I've been looking around for other projects that people have started specifically for publishing in Django... Are there any publishing specific Dj...

Is it possible to replace values in a queryset before sending it to your template?

Hi Guys, Wondering if it's possible to change a value returned from a queryset before sending it off to the template. Say for example you have a bunch of records Date | Time | Description 10/05/2010 | 13:30 | Testing... etc... However, based on the day of the week the time may change. However this is static. For example on a monday ...

Django Model: many-to-many or many-to-one?

I'm just learning django and following a tutorial. I have a Link and a Bookmark. Unlike the tutorial I'm following, I would like a link to be associated with only one Bookmark, but a Bookmark can have multiple links. Is this the way to setup the model? class Link(models.Model): url = models.URLField(unique=True) bookmark = model...