In chapter 8 of the Django book there is an example showing a fundamental view wrap method, which receives another view method passed in from any single arbitrary URLconf:
def requires_login(view):
def new_view(request, *args, **kwargs):
if not request.user.is_authenticated():
return HttpResponseRedirect('/accoun...
In this:
class Administrator(models.Model):
user = models.OneToOneField(User, primary_key=True)
account = models.ForeignKey(Account)
class Meta:
unique_together = (('account', 'self.user.username'),)
The self.user.username part is obviously incorrrect. However, in this:
class Administrator(User):
account = mo...
I'm trying to store pickled objects in a django models.TextField.
But when I try to unpickle my data (with loads) I get "insecure string pickle".
What can I do about this?
...
What is the appropriate way to create an instance of the following two models
class Administrator(models.Model):
user = models.OneToOneField(User, primary_key=True)
account = models.ForeignKey(Account)
class Account(models.Model):
owner = models.OneToOneField(Administrator)
Both require each other. An account cannot exist...
Hi folks,
I'm building this app in Python with Django.
I would like to give parts of the site wiki like functionality,
but I don't know how to go on about reliability and security.
Make sure that good content is not ruined
Check for quality
Prevent spam from invading the site
The items requiring wiki like functionality are just a f...
Hi there,
my project was not working properly when switching from my local development (sqlite3) to mysql. After some inspection, I found that Django seems to use 32-bit-ints for IntegerField on mysql, but I need 64 bit. Is there any way to achieve this?
...
I am attempting to create a semi-dynamic aggregate function that will return the sums of all fields within a list. The assumption is that running get_query_set() will return a filtered query that contains all the fields in the list and some others that may not play so well with a Sum aggregate (date fields, char fields, Foreign Keys, etc...
hi i am using the following models to build a database
from django.db import models
from django.contrib import admin
class Team(models.Model):
"""Model docstring"""
slug = models.SlugField(max_length=200)
Team_ID = models.AutoField(primary_key=True)
Team_Name = models.CharField(max_length=100,)
College = models.Ch...
i have a model that is having multiple many to many relation to another model it is as follows:
class Match(models.Model):
"""Model docstring"""
Match_Id = models.AutoField(primary_key=True)
Team_one = models.ManyToManyField('Team',related_name='Team one',symmetrical=False,)
Team_two = models.ManyToManyField('Team',related_nam...
Hello!
I am currently working on a Django/Pinax application (I'm sure my question is not pinax-specific, that's why Pinax's not mentioned in the theme title), and trying to figure out how the whole framowork works. Right now I have to write a view to pass data to a tempate. I've only seen it done in the django manual: there ObjectName.o...
The Django docs only list examples for overriding save() and delete(). However, I'd like to define some extra processing for my models only when they are created. For anyone familiar with Rails, it would be the equivalent to creating a :before_create filter. Is this possible?
...
I'm using generic types in my Profile model:
user_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
details = generic.GenericForeignKey('user_type', 'object_id')
But now I want to check if a user is a certain type from within my template. I can get the user type with {{ user.get_profile.user_type }} but t...
Hi,
I'm trying to do something like these proposed signal decorators. In addition to having a decorator that connects the decorated method to a signal (with the signal's sender as an argument to the decorator), I would like to use the decorator on class methods.
I'd like to use the decorator like so:
class ModelA(Model):
@connec...
Hi, I've this django model:
from django.db import models
class MyModel(models.Model):
foo_it = model.CharField(max_length=100)
foo_en = model.CharField(max_length=100)
def save(self):
print_all_field_starting_with('foo_')
super(MyModel, self).save()
So I want to get all field starting with foo (as an exam...
I have a model with lots of say CharField fields, that I would like to edit in the admin.
The problem is that each field takes up one line. How should I make them display like this (horizontally):
(they are not foreign keys)
...
I have this Model in django :
class Post(models.Model):
title = models.CharField(max_length=255)
category = models.CharField(max_length=255)
I would like to get the different values that are used in the category attribute.
For example, if we consider this db :
Post(title = "title 1", category="foo")
Post(title = "title 2", c...
I have a class called BankAccount as base class. I also have CheckingAccount and SavingsAccount classes that inherit from BankAccount.
BankAccount is not an abstract class but I do not create an object from it, only the inheriting classes.
Then, I execute a query like this:
account = BankAccount.objects.get(id=10)
How do I know if a...
I have many pk-value in a dictionary and I want to update the object with his new value.
to_update = [{'id':id1,'value':value1}, ... ]
Now i'm doing this:
for t in to_update:
Mymodel.objects.filter(pk=t['id']).update(myfield=t['value'])
I think thant i can do this in a better way, but i didn't find it.
Thank You
...
What I'm aiming for is a checkbox option in the list_display of the admin which will accept only selected checkbox (essentially a radiobox) and deselct the others.
The model field is not a ForeignKey.
Alternatively is there a way to do this in the model object list as one of the fields?
The example is of an image bank from which the c...
good day guys!
in project, among others, have models:
class Category(models.Model):
name = models.CharField(max_length = 50, blank = False, null = False)
def __unicode__(self):
return "Category %s" % self.name
class Meta:
db_table = "categories"
managed = False
class Site(models.Model):
user...