I want to use the Django admin interface for a very simple web application but I can't get around a problem that should not be that hard to resolve ..
Consider the following:
class Contact(models.Model):
name = models.CharField(max_length=250, blank=False)
created_by = models.ForeignKey(User, blank=False)
I can't find a way t...
I've got a model like this
def upload_location(instance, filename):
return 'validate/%s/builds/%s' % (get_current_user(), filename)
class MidletPair(models.Model):
jad_file = models.FileField(upload_to = upload_location)
jar_file = models.FileField(upload_to = upload_location)
upload_to=tempfile.gettempdir()
How...
I have started work on a local app for myself that runs through the browser. Having recently gone through the django tutorial I'm thinking that it might be better to use django rather than just plain python.
There's one problem, I have at least 20 models and each will have many functions. Quite simply it's going to create one huge model...
I'd like to be able to include a reference to the currently authenticated user with a Note when working with Notes from the admin interface. The model would look something like:
from django.db import models
from django.contrib.auth.models import User
from datetime import datetime
class Note(models.Model):
datetime = models.DateTi...
Hello,
I have a model with a created_by field that is linked to the standard Django User model. I need to automatically populate this with the ID of the current User when the model is saved. I can't do this at the Admin layer, as most parts of the site will not use the built-in Admin. Can anyone advise on how I should go about this?
...
I'm developing using Django on Windows. I have a model with an imagefield, and use a form to fill it. Images get uploaded without problem. The problem occurs when I attempt to show an uploaded image inside a template by coding this:
<img src ='{{object.image.url}}'/>
(object is an instance of the relevant model, and image is the name ...
I have a model that has a field named "state":
class Foo(models.Model):
...
state = models.IntegerField(choices = STATES)
...
For every state, possible choices are a certain subset of all STATES. For example:
if foo.state == STATES.OPEN: #if foo is open, possible states are CLOSED, CANCELED
...
if foo.state == STA...
Here's a Django model class I wrote. This class gets a keyerror when I call get_object_or_404 from Django (I conceive that keyerror is raised due to no kwargs being passed to __init__ by the get function, arguments are all positional). Interestingly, it does not get an error when I call get_object_or_404 from console.
I wonder why, and ...
We're running django alongside - and sharing a database with - an existing application. And we want to use an existing "user" table (not Django's own) to store user information.
It looks like it's possible to change the name of the table that Django uses, in the Meta class of the User definition.
But we'd prefer not to change the Dja...
Given a model with ForeignKeyField (FKF) or ManyToManyField (MTMF) fields with a foreignkey to 'self' how can I prevent self (recursive) selection within the Django Admin (admin).
In short, it should be possible to prevent self (recursive) selection of a model instance in the admin. This applies when editing existing instances of a mod...
When I try to put a zlibbed string in models.TextField
>>> f = VCFile(head = 'blahblah'.encode('zlib'))
>>> f.save()
it fails:
...
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x9c in position 1: unexpected code byte. You passed in 'x\x9cK\xcaI\xccH\x02b\x00\x0eP\x03/' (<type...
hi,
class Status(models.Model):
someid = models.IntegerField()
value = models.IntegerField()
status_msg = models.CharField(max_length = 2000)
so my database look like:
20 1234567890 'some mdg'
20 4597434534 'some msg2'
20 3453945934 'sdfgsdf'
10 4503485344 'ddfgg'
so I have to fetch values contain a givin...
How do you define a specific ordering in Django QuerySets?
Specifically, if I have a QuerySet like so: ['a10', 'a1', 'a2'].
Regular order (using Whatever.objects.order_by('someField')) will give me ['a1', 'a10', 'a2'], while I am looking for: ['a1', 'a2', 'a10'].
What is the proper way to define my own ordering technique?
...
This is a newbie theory question - I'm just starting to use Python and looking into Django and orm. Question: If I develop my objects and through additional development modify the base object structures, inheritance, etc. - would Django's ORM solution modify the database automatically OR do I need to perform a conversion (if the app is ...
I'm new, and confused. I want to create a module that keeps track of the "top hit" instances of both an article and a blog model. I don't want to touch the code for the article or blog models. Is this a candidate for middleware? looking at the HttpRequest.path?
Thanks
...
Hi! I have this models:
class Project(models.Model):
users = models.ManyToManyField(User, through='Project_User')
class Project_User(models.Model):
project = models.ForeignKey('Project')
user = models.ForeignKey(User)
property = models.BooleanField()
Not all Projects have own Project_User rows.
Thing, what I need is ...
The default Django's User model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers.
I also don't like default character set for user name that is validated in D...
Hi,
I am newbie at Django.I have model with a custom method.In view I am
retrieving a single object.See below --
My model
class Problem(models.Model):
problem = models.CharField(max_length=100)
solution=models.CharField(max_length=500)
def unicode(self):
return self.problem
def retrieve_rankdata(self):
...
I want to trigger a special action in the save() method of a Django model object when I'm saving a new record (not updating an existing record.)
Is the check for (self.id != None) necessary and sufficient to guarantee the self record is new and not being updated? Any special cases this might overlook?
...
I have made a inline named as Fooinline. This inline was working fine in Django 1.02 but as soon as I upgraded to Django 1.1 it started giving an error:
**TypeError at /admin/casd/aaas/4028cb901dd9720a011deadd85e8007f/
__init__() got an unexpected keyword argument 'request'**
My Fooinline code is:
class FooInline(InlineModelAdmin):
...