I want to ensure that a user editing a particular model is saved in that models updated_by (FK User) field.
I'm using mostly ModelForms (not necessarily the built in Admin), and wondering:
In what cases would I need to override ModelAdmin.save_model() or ModelAdmin.save_formset()?
Or, is that doing it wrong? If it's just the models...
This is my model:
class Author(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
middle_name = models.CharField(max_length=200, blank=True)
def __unicode__(self):
return full_name
def _get_full_name(self):
"Returns the person's full name."
...
I have two related models (one to many) in my django app and When I do something like this
ObjBlog = Blog()
objBlog.name = 'test blog'
objEntry1 = Entry()
objEntry1.title = 'Entry one'
objEntry2 = Entry()
objEntry2.title = 'Entry Two'
objBlog.entry_set.add(objEntry1)
objBlog.entry_set.add(objEntry2)
I get an error which says "null ...
I've got a model like this:
class Talk(BaseModel):
title = models.CharField(max_length=200)
mp3 = models.FileField(upload_to = u'talks/', max_length=200)
seconds = models.IntegerField(blank = True, null = True)
I want to validate before saving that the uploaded file is an MP3, like this:
def is_mp3(path_to_...
I am new to the Django framework.
On Django's admin index page I'd like to get rid of the "s" at the end of my model names.
Example:
<div class="module">
<table summary="Models available in the my application.">
<caption><a href="" class="section">My application</a></caption>
<tr>
<th scope="row"><a ...
I'm looking for a way to do asynchronous data processing with a daemon that uses Django ORM. However, the ORM isn't thread-safe; it's not thread-safe to try to retrieve / modify django objects from within threads. So I'm wondering what the correct way to achieve asynchrony is?
Basically what I need to accomplish is taking a list of use...
Having a ModelFormSet built with modelformset_factory and using a model with an optional ForeignKey, how can I make empty (null) associations to validate on that form?
Here is a sample code:
### model
class Prueba(models.Model):
cliente = models.ForeignKey(Cliente, null = True)
valor = models.CharField(max_length = 20)
### vi...
I have a many-to-many field on one of my models and a ModelForm to represent it. I have it in a template but it shows up as a multiple select field. I need it to show up as a CharField so the user can put in comma-delimited values. Is there any way to do this?
...
I am working through the Django tutorials, and now I am at creating a poll.
The code below works fine until I want to create choices, where for some reason I always get this error message:
line 22, in __unicode__
return self.question
AttributeError: 'Choice' object has no attribute 'question'
What am I doing wrong?
Here's my code...
This is are my models i want to relate. i want for collection to appear in the form of occurrence.
class Collection(models.Model):
id = models.AutoField(primary_key=True, null=True)
code = models.CharField(max_length=100, null=True, blank=True)
address = models.CharField(max_length=100, null=True, blank=True)
collection_...
what Im looking to do is to have a link on the name of a field of a model. So when im filling the form using the admin interface i can access some information.
I know this doesn't work but shows what i want to do
class A(models.Model):
item_type = models.CharField(max_length=100, choices=ITEMTYPE_CHOICES, verbose_name="<a href='htt...
Hi SO's
I have a question on good database design practices and I would like to leverage you guys for pointers. The project started out simple.
Hey we have a bunch of questions we want answered for every project (no problem)
Which turned into...
Hey we have so many questions can we group them into sections (yup we can do t...
What is the best approach to extending the Site model in django? Creating a new model and ForeignKey the Site or there another approach that allows me to subclass the Site model?
I prefer subclassing, because relationally I'm more comfortable, but I'm concerned for the impact it will have with the built-in Admin.
...
In order to save time moving data I pickled some models and dumped them to file. I then reloaded them into another database using the same exact model. The save worked fine and the objects kept their old id which is what I wanted. However, when saving new objects I run into nextval errors.
Not being very adept with postgres, I'm no...
Question
Why can data loaded via the initial_data.yaml fixture populate a SlugField with a slug containing a period and not generate an error?
Code
Here's an excerpt of the model:
class Project(models.Model):
slug_code = models.SlugField(max_length=15)
Here's the applicable initial_data.yaml excerpt:
- model: myapp.project
...
It used to work, and now it doesn't. python manage.py syncdb no longer makes tables for my app.
From settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.myapp',
'django.contrib.admin',
)
What could I be doing wrong? Th...
I'm trying to extend the basic user registration form and profile included in satchmo store, but I'm in problems with that.
This what I've done:
Create a new app "extendedprofile"
Wrote a models.py that extends the satchmo_store.contact.models class and add the custom name fields.
wrote an admin.py that unregister the Contact class ...
Here, I am a bit confused with forms in Django. I have information for the form(a poll i.e the poll question and options) coming from some db_table - table1 or say class1 in models. Now the vote from this poll is to be captured which is another model say class2. So, I am just getting confused with the whole flow of forms, here i think. H...
I've been searching here and there, and based on this answer I've put together what you see below.
It works, but I need to put some stuff in the user's session, right there inside authenticate.
How would I store acme_token in the user's session, so that it will get cleared if they logged out? The request object is not available in this ...
I have a base LoggedEvent model and a number of subclass models like follows:
class LoggedEvent(models.Model):
user = models.ForeignKey(User, blank=True, null=True)
timestamp = models.DateTimeField(auto_now_add=True)
class AuthEvent(LoggedEvent):
good = models.BooleanField()
username = models.CharField(max_length=12)
c...