I have 3 models in a Django app, each one has a "hostname" field. For several reasons, these are tracked in different models.:
class device(models.Model):
...
hostname = models.CharField(max_length=45, unique=True, help_text="The hostname for this device")
...
class netdevice(models.Model):
...
hostname = models.CharField(max_length=4...
Hello,
assume I have this little model:
class Deal(models.Model):
purchases = models.IntegerField(default=0)#amount of purchases so far
increase_purchases(self,to_add):
self.update( purchases =self.purchases + to_add)
when I try to use this increase_purchases model from shell:
>>> x = Deal.objects.get(id=1)
>>> x.inc...
Hi,
I want to get rid of two related managers in a Model because I will never need them. How can I get rid of them?
This is my User Profile:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
...
default_upload_container=models.ForeignKey(Container,related_name='idontcare')
default_quer...
How can I get a list of all the model objects that have a ForeignKey pointing to an object? (Something like the delete confirmation page in the Django admin before DELETE CASCADE).
I'm trying to come up with a generic way of merging duplicate objects in the database. Basically I want all of the objects that have ForeignKeys points to ...
I have 2 models and i want ,any instances on class 1 in class 2 how do i do it in django models ...and i tried using manytomany field but the problem is when i add a new object it will have that manytomany field already there (which i dont want ) ...any idea how do i do this ...
...
5,1-8 Top
class customerdetails(models.Model):
1 = models.DecimalField(max_digits=5, decimal_places=2)
2= models.IntegerField()
3 = models.DecimalField(max_digits=5, decimal_places=2)
11 = models.DecimalField(max_digits=5, decimal_places=2)
...
In Django,
I can do value(), and then distinct() to group by.
A
{
Foreign Key B
}
B
{
String name
}
However, is it possible to group using a related object's data? I.e. In the above relation, can I group A by B's name?
...
Currently, I have 3 models, A, B and C
C has foreign key to B
B has foreign key to A
class C(models.Model):
name = models.CharField(max_length=50, db_index=True, unique=True)
b = models.ForeignKey(B)
class B:
...similar to C
class A
...similar to C except for the FK
However, the SQL generated by manage.py sqlindexes app doesn...
Hello how do i change the date format in models
for Eg: i have
date = models.DateField(blank=True, null=True)
by default it yyyy-mm-dd format how do i change it to dd-mm-yyyy format
...
Hi.
Say we have models
from django.db import models
class AutomaticModel(models.Model):
others = models.ManyToManyField('OtherModel')
class ManualModel(models.Model):
others = models.ManyToManyField('OtherModel', through='ThroughModel')
class OtherModel(models.Model):
pass
class ThroughModel(models.Model):
pblm = mo...
Greetings,
Assume I have such model:
class Foo(models.Model):
type = models.ForeignKey(Type)
start_time = models.DateTimeField()
end_time models.DateTimeField()
For each Foo object that is having the same type, I need this time interval (end_time - start_time) to be unique so that creation of a second Foo with a clashing ...
In Django is there a way to force admin users to choose to fill one of a few ForeignKeys and not more than one?
I have a model something like :
class URL(models.Model):
...
links = models.URLField(_('Google Links'),verify_exists=True,unique=True)
project = models.ForeignKey(Project,blank=True,null=True)
category = model...
I'm creating a new model called Tickets which I want to ensure always has a valid userID assigned to it.
I'm using AUTH_PROFILE_MODULE to setup the profile which also gives the error NameError: name 'User' is not defined when I try to run syndb.
How do I setup a foreign key to make sure this always is the case?
## tickets/models.py
c...
I have inserted a definition for a view in $template_dir/sql/$someTableName.sql file. (create or replace view) so every time I run syncdb, the db views are created.
Can I create in models.py a python class which accesses that view?
Is it better practice to just use python's raw sql functionality instead?
---EDIT---
Another problem I ...
I have this:
Class A(models.Model):
name = models.CharField(max_length=50)
Class B(models.Model):
a = models.ForeignKey(A)
class C(models.Model):
a = models.ManyToManyField(A)
When i need the attribute a in an object of C:
related_manager = getattr(object_c,'a')
and this give me a ManyRelatedManager but the proble...
Can a field of type models.PositiveIntegerField contain a 0 value? I'm doing something like:
points = models.PositiveIntegerField(default=0)
Thanks,
I know I should try ir myself, but I haven't a Django environment here.
...
First, the code of my tests.py
def test_get_current(self):
m = Member.objects.create(...)
q = Question.objects.create(name="q1", text="q1", start_datetime=self.day_before, close_datetime=self.day_after, type=self.type)
r = Response.objects.create(question=q, text='response')
expected = q, None
#self.assertEquals(exp...
Does anyone have a list of things they do to associate some model with a user?
I.e. if a blog entry has a user, you have to do a few things:
- Add a foriegnkey field
- Make the foreign key field editable = False
- On save/load make sure that request.user matches entry.user
This is what I could come up with. Is there an easier way to do...
I have django objects:
class Event(models.Model):
title = models.CharField(max_length=255)
event_start_date = models.DateField(null=True, blank='true')
...
class RegistrationDate(models.Model):
event = models.ForeignKey(tblEvents)
date_type = models.CharField(max_length=10, choices=registration_date_type)
start_dat...
I have a method on my user registration form that looks like this:
def save(self):
user = User(
username = self.cleaned_data['username'],
email = self.cleaned_data['email1'],
first_name = self.cleaned_data['first_name'],
last_name = self.cleaned_data['last_name'],
)
user.set_password(self.clea...