I have the following models: http://slexy.org/view/s20T8yOiKZ
from mxutils.cms_services import generate_secid
from django.db import models
from django.contrib import admin
from django import forms
class World(models.Model):
title = models.CharField(max_length=150)
secid = models.SlugField(max_length=1000, editable=False)
el...
Hi,
is there a way to do the following in one Django query?
MyModel.filter(attr=a).values('attr','fields','of','interest').annotate(count=Count('id'))
MyModel.filter(attr=b).values('attr','fields','of','interest').annotate(count=Count('id'))
edit:
I need separate counts for a and b. MyModel.filter(attr__in=(a,b))... or MyModel.filter...
Hi folks,
what I'm trying to do is this:
get the 30 Authors with highest score ( Author.objects.order_by('-score')[:30] )
order the authors by last_name
Any suggestions?
...
In one of my Django models, I override the save function. I do this to get the user's username. But that keeps failing.
this is what i did:
def save(self, *args, **kwargs):
self.slug = slugify('%s' % (self.question))
if not self.id:
self.publish_date = datetime.datetime.now()
self.publisher = self.request.us...
I'd like to do something like this:
class Task(models.Model):
...
created_by = models.ForeignKey(User, default=[LoggedInUser] blank=True, null=True, related_name='created_by')
Is this possible? I couldn't find what's the proper way to get the logged in user, apart from doing request.user, in a view, which doesn't seem to work here.
PS...
hi can any body send me a complete tutorial about how to create a model form in django.
i tried to create a form from here .
"http://docs.djangoproject.com/en/dev/topics/forms/modelforms/"
but it returns an error saying
"name 'ModelForm' is not defined"
any suggestions
plzzzz
...
Given the following Contribution model:
class Contribution(models.Model):
start_time = models.DateTimeField()
end_time = models.DateTimeField(null=True)
is it possible, using the Django database API, to reproduce the following SQL statement?
SELECT SUM(end_time - start_time) AS total_duration FROM contribution;
I've figured...
I'm trying to create a Django model that handles the following:
An Item can have several Names.
One of the Names for an Item is its primary Name, i.e. the Name displayed given an Item.
(The model names were changed to protect the innocent.)
The models.py I've got looks like:
class Item(models.Model):
primaryName = models.OneToO...
Models (disregard typos / minor syntax issues. It's just pseudo-code):
class SecretModel(models.Model):
some_unique_field = models.CharField(max_length=25, unique=True) # Notice this is unique.
class MyModel(models.Model):
secret_model = models.OneToOneField(SecretModel, editable=False) # Not in the form
spam = models.Char...
Introduction
I have the following code which checks to see if a similar model exists in the database, and if it does not it creates the new model:
class BookProfile():
# ...
def save(self, *args, **kwargs):
uniqueConstraint = {'book_instance': self.book_instance, 'collection': self.collection}
# Test for oth...
hi
i have the following models setup
class Player(models.Model):
#slug = models.slugField(max_length=200)
Player_Name = models.CharField(max_length=100)
Nick = models.CharField(max_length=100, blank=True)
Jersy_Number = models.IntegerField()
Team_id = models.ForeignKey('Team')
Postion_Choices = (
('M', ...
I'm looking a Django app I'm looking for an app that that allows for management and integration of footnotes for articles
just wondering if anyone had seen something around...
...
hi i have to following model
class Match(models.Model):
Team_one = models.ForeignKey('Team', related_name='Team_one')
Team_two = models.ForeignKey('Team', related_name='Team_two')
Stadium = models.CharField(max_length=255, blank=True)
Start_time = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True...
i have the following function to override the default save function in a model match
def save(self, *args, **kwargs):
if self.Match_Status == "F":
Team.objects.filter(pk=self.Team_one.id).update(Played=F('Played')+1)
Team.objects.filter(pk=self.Team_two.id).update(Played=F('Played')+1)
if self.Winner !="":
...
I've defined a model which contains a link an image. Is there a way to display the image in the model items list? My model looks like this:
class Article(models.Model):
url = models.CharField(max_length = 200, unique = True)
title = models.CharField(max_length = 500)
img = models.CharField(max_length = 100) # Contains path t...
I'm trying to use the Django ORM in some standalone screen scraping scripts. I know this question has been asked before, but I'm unable to figure out a good solution for my particular problem.
I have a Django project with defined models. What I would like to do is use these models and the ORM in my scraping script. My directory structur...
This post relates to this:
http://stackoverflow.com/questions/520421/add-row-to-inlines-dynamically-in-django-admin
Is there a way to achive adding inline formsets WITHOUT using javascript? Obviously, there would be a page-refresh involved.
So, if the form had a button called 'add'...
I figured I could do it like this:
if request.met...
When i attempt to add a file with russian symbols in name to the model instance through default instance.file_field.save method, i get an UnicodeDecodeError (ascii decoding error, not in range (128) from the storage backend (stacktrace ended on os.exist). If i write this file through default python file open/write all goes right. All fil...
I have 2 models:
class A(Model):
#Some Fields
objects = ClassAManager()
class B(A):
#Some B-specific fields
I would expect B.objects to give me access to an instance of ClassAManager, but this is not the case....
>>> A.objects
<app.managers.ClassAManager object at 0x103f8f290>
>>> B.objects
<django.db.models.manager.Mana...
Hi,
I'd like to validate user input with regular expression in Django Admin CharField... How is it possible?
Thanks in advance,
Etam.
...