I have a model which has a date time field:
date = models.DateField(_("Date"), default=datetime.now())
When I check the app in the built in django admin, the DateField also has the time appended to it, so that if you try to save it it returns an error. How do I make the default just the date? (datetime.today() isn't working either)
...
A couple of times I've run into a situation, when at save time I need to know which model fields are going to be updated and act accordingly.
The most obvious solution to this is to take the primary key field and retrieve a copy of the model from the database:
class MyModel(models.Model):
def save(self, force_insert=False, force_u...
Is it advisable to use get_prep_value() in my Django Field subclass to do this (my custom field is a sub-class of DecimalField):
def get_prep_value(self, value):
from decimal import Decimal
value = Decimal(value.replace('$', ''))
return super(MyCustomField, self).get_prep_value()
Does this pose a problem with django's Mode...
I have a model with a ManyToManyField with a through model in which there is a boolean field that I would like to filter upon.
from simulations.models import *
class DispatcherManager(models.Manager):
use_for_related_fields = True
def completed(self):
original = super(DispatcherManager,self).get_query_set()
re...
Say I have a model like:
from django.db import models
USER_TYPE_CHOICES = (
(1, 'Free'),
(2, 'Paid'),
)
class Account(models.Model):
name = models.CharField(max_length=20)
user_type = models.IntegerField(default=1, choices=TYPE_CHOICES)
and in a template I want to test the user_type to show a special section if the u...
Hello everyone,
I have a field in a model that I want users to feel like they can write an arbitrary amount of text in. Django provides a CharField and a TextField in the models. I assume that the difference is that one of them is a char(max_length) and the other is a varchar internally.
I am tempted to use the TextField, but since it ...
I generally check if obj.pk to knwo if the objects is saved. This wont work however, if you have primary_key = True set on some fields. Eg I set user = models.OneToOneField(User, primary_key=True) on my UserProfile.
What is the canonical way to find out if a Django model is saved to db?
...
So I'm trying to create a new feed within the Admin page and its
crashing with the error IntegrityError: lifestream_feed.lifestream_id
may not be NULL, form['lifestream'] is set but
form.instance.lifestream is not.
form.fields even shows that lifestream is a django.forms.models.ModelChoiceField
Here is the code:
class FeedCreationFo...
I'm looking to implement a zipcode field in django using the form objects from localflavor, but not quite getting them to work. I want to have a zipcode field in a form (or ModelForm in my case), but the fields never validate as a zipcode when calling _get_errors() on the form object. The way I'm implementing it seems right to me but is...
Hi at all. I have a project with 2 applications ( books and reader ).
Books application has a table with 4 milions of rows with this fields:
book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
To avoid to query the database with 4 milions of rows, I am thinking to divide it by subject ( ...
So in my Django project I have a few different apps, each with their own Models, Views, Templates, etc. What is a good way (the "Django" way) to have these Apps communicate?
A specific example would be a Meetings App which has a model for Meetings, and I have a Home App in which I want to display top 5 Meetings on the home page.
Should...
Scenario:
class BaseClass(models.Model):
base_field = models.CharField(max_length=15, default=None)
class SubClass(BaseClass):
# TODO set default value if base_field's value is None
...
ie. I need to be able to load a fixture into the database, providing a default value only if the base_field is None. Any help greatly app...
Hi all,
I have this structure of model objects:
Class A :
b = models.ManyToManyField("B")
Class B:
c = models.ForeignKey("C)
d = models.ForeignKey("D)
Class C:
d = models.ForeignKey("D)
This is the query I'm trying to get:
I want to get all the B objects of object A , then in each B object to make comparison between the D object and...
well it's quiet simple.
2 models with ManyToMany relation:
class Artist(models.Model):
name = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True,
help_text='Uniq value for artist page URL, created from name')
birth_name = models.CharField(max_length=100, blank=True)
c...
Hi,
I have an Invoice model with a boolean field: is_overdue . This field is set to True if the user did not receive a payment and the due_date is before the date of today.
Now I want to accomplish that this field is regularly updated. Ok one possibility is to update the field when the save method is called.
But how can I ensure that...
Hello,
I'm trying to create a product code (in the admin) by combining elements from two other fields - one of which is a ManyToManyField. I'd like to iterate through that field to find out if a specific product option has been chosen, and append a variation of it to that non-editable product code, like so:
class ShirtColorClass(models...
Hi,
I have a model called Product with a custom property:
def _get_active(self):
o = get_option()
if self.date_expiration == None:
return True
if self.date_expiration <= o.working_month:
return False
return True
active = property(_get_active)
... and in one of my methods, I have this line:
products = ...
I'm attempting to use a similar Category implementation to this one in the Django Wiki. I'm wondering what the Django way of doing a search to pull all objects associated with a parent category. For example, if I have a category "TV" and it has subcategories "LED", "LCD", and "Plasma", how would I be able to easily query for all TV's w...
I'm trying to fill in the value of a foreign key entry in one of my models using a value stored as session data...it all works well but when I try to access the record from the admin I get this error:
Caught an exception while rendering: coercing to Unicode:
need string or buffer, Applicant found
Where Applicant is the model linke...
Hi I am new to Django working on Google App Engine.
class StudentAddress(db.Model):
name=db.UserProperty()
address=db.StringProperty(verbose_name='Home Address')
class StudentAddressForm(djangoforms.ModelForm):
class Meta:
moddel = StudentAddress
When the form is displayed, verbose name comes like this : Home address
Ho...