Hi All,
So im wanting to extend the django auth.User model to add extra fields. Ive read a few articles here and there, and am almost there.
Im just trying to make the signup form at the moment. So a new user can sign up. I can get the new User created but when I come to save the UserProfile object to the database it fails citing
Cann...
Hello,
I have a Promotion model that contains a promotion codes and a foreignkey to a purchase model Class.
Here is the model:
class Promotion(models.Model):
purchase = models.ForeignKey('Purchase')
promotion_code = models.CharField(max_length=20)
def promotion_code_generate(self): #returns a string based promotion code with 7 leng...
Hello,
I want to set the "default" value as a randomly generated String for the promotion_code part of my Promotion model, for that the code_generate function is used.
The issue with the code below that it seems like default=code_generate() generates this random string once every server start thus assigning the same value. I can see th...
The problem is the default User model does not have some very useful options given to the fields e.g unique=True to the email field.
I read this question: http://stackoverflow.com/questions/1817244/django-override-default-user-model-method, and checked Proxy Model concept, but with no effect.
At first I tried:
from django.contrib.auth...
Consider the following model:
class Message(models.Model):
other_model = models.ForeignKey(OtherModel) # OtherModel has owner field
thread_user = models.ForeignKey(User)
posting_user = models.ForeignKey(User)
message = models.TextField()
What I'm trying to do is have private messaging between two users on a third obje...
Sorry if this is a dumb way to ask this...
I have a generic list view for the homepage of a site, and would like to use a "homepage" model for informative text on that same page...is it possible? Thanks for your help.
models.py
from django.db import models
class School(models.Model):
school_name = models.CharField(max_length=250,...
I have 2 models. I run manage.py syncdb but it creates only id fields for 2 models. How to make it generate the remaining fields? Please kindly advise. Your help is much appreciated!
Here's my models.py:
from django.db import models
GENDER_CHOICES = (
('M', 'Male')
, ('F', 'Female')
)
ACTIVATION_CHOICES = (
('Y', 'Activat...
How to create models and tables with Compound/Composite primary/unique key with Django?
...
I'm trying to use a User model inheritance in my django application. Model looks like this:
from django.contrib.auth.models import User, UserManager
class MyUser(User):
ICQ = models.CharField(max_length=9)
objects = UserManager()
and authentication backend looks like this:
import sys
from django.db import models
from django...
Hello, I have these models:
def Foo(Models.model):
size = models.IntegerField()
....some other vars...
def is_active(self):
if ...checks something here...
return True
else:
return False
def Bar(Models.model):
foo = models.ForeignKey("Foo")
....some other vars...
Now...
I'm using Django 1.1 with MySQL as the database.
I have a model similar to the following:
class Review(models.Model):
venue = models.ForeignKey(Venue, db_index=True)
review = models.TextField()
datetime_created = models.DateTimeField(default=datetime.now)
I'd like to query the database to get the total number of reviews...
I have Admin User extended/subclassed by Teacher class.
How to prevent Teachers from seeing and changing other Teachers' profile data and Teachers are able to change their own records/rows only? Thanks in advance!
...
By default Django admin site shows all records of a related model/table for viewing. How can I show only the records that meet certain criteria?
...
Do you know the default isolation level of the transactions used in Django?
Is it possible to set the isolation level in the database independent way?
I'm mainly interested in mysql and postgres.
...
I'm using following model to store info about pages:
class Page(models.Model):
title = models.TextField(blank = False, null = False)
New data saves correctly, I'm saving Unicode data there (lots of non-ASCII titles).
But when I'm performing query:
page = Page.objects.filter(id = 1)
page.title looks odd:
u'\u042e\u0449\u0435\u0...
While subclassing db.models.Model, sometimes it's essential to add extra checks/constraints. E.g. I have an Event model with start_date and end_date. I want to add validation into the fields or the model so that end_date > start_date. How many possible ways to do this? At least I know this can be done outside the models.Model inside the ...
I've been able to do this through the django environment shell, but hasn't worked on my actual site. Here is my model:
class ShoeReview(models.Model):
def __unicode__(self):
return self.title
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
keywords = models.Te...
Hi i am using
image = models.ImageField()
How do i view this image in admin page as soon i upload
...
I can't figure out how I'm supposed to order these models that have a M2M relationship.
When I try to syncdb, I can't because the Model related model is not in the namespace yet, so I get:
NameError: name 'FavoriteQuestion' is not defined
If I switch places, I get:
NameError: name 'UserProfile' is not defined
class UserProfile(models....
I have a django model in use on a production application and I need to change the name and data type of the field with zero downtime to the site. So here is what I was planning:
1) Create the new field in the database that will replace the original field
2) Everytime an instance of the Model is loaded, convert the data form the origina...