I like to normalize things the most I can in a database. This isn't obviously the best thing for performance, but it helps with flexibility, reporting, etc. I've found it hard to justify in a recent case though which has caused me to build a model that has 25 fields in it. Is this "too big"? Or, is that quite normal. Of course the obviou...
I'm setting up a data model in django using multiple-table inheritance (MTI) like this:
class Metric(models.Model):
account = models.ForeignKey(Account)
date = models.DateField()
value = models.FloatField()
calculation_in_progress = models.BooleanField()
type = models.CharField( max_length=20, choices= METRIC_TYPES )...
I wanted to provide unique ID for different categories of models in my db. So I've introduced a dummy model :
class GUUID(models.Model):
guuid = models.PositiveSmallIntegerField(_(u"Dummy GUUID"), default=1)
and in model that I want to have unique ID:
class Event(models.Model):
unique = models.IntegerField(blank=False, edita...
I have a model with a unique integer that needs to increment with regards to a foreign key, and the following code is how I currently handle it:
class MyModel(models.Model):
business = models.ForeignKey(Business)
number = models.PositiveIntegerField()
spam = models.CharField(max_length=255)
class Meta:
unique_to...
I want to do something like
for field in field_list:
my_table.field = new_value
Couldn't find any documentation on how to do the above with a variable.
...
Hey everyone,
Here is my problem. I have a model Project, that has a quote field in it. When a new instance of project is created I need to append the last 2 digits of the year plus a hyphen onto the start of the "quote" field. Ex. 2010 = "10-". Im just not quite sure how to start it?
As of right now I have hard coded in "10-" in a...
Hi,
I'm writing a web app using the django framework and I was just wondering what are the pros/cons of using the built-in django.contrib.auth.models.User model over my own user model?
Please explain in terms of performance, scalability and security.
Many thanks
...
When using the Django ORM from an external shell, using a model with a ForeignKey field an ImportError is thrown when assigning to it.
And here is a paste of my shell sessions both from ./manage.py shell and from normal python shell.
bradyrj@machine:~/workspaces/django/shellgame$ python manage.py shell
Python 2.6.6 (r266:84292, Sep 15 ...
I'm trying to save a new object from a django model using a POST data querydict. This is part of a PISTON handler. I've seen this done in numerous examples, but I just can't get it to work.
Here is my code:
class FestHandler(BaseHandler):
model = Deal
def create(self, request):
"""
Creates a new fest.
...
I'm building a page where the users can choose which rows to edit. After they select their rows and hit "edit" I'd like to present them with a modelformset_factory showing an editable version of all the rows the user selected.
My problem is I believe I need to turn this list of primary keys that I get back into a queryset suitable for u...
def by_this(self):
return super(MyModelManager, self).get_query_set().filter(this=True)
def by_that(self):
return super(MyModelManager, self).get_query_set().filter(that=True)
If i do MyModel.objects.by_this() or by_that() it works.
But i want to do: MyModel.objects.by_this().by_that()
...
I am subclassing an existing model. I want many of the members of the parent class to now, instead, be members of the child class.
For example, I have a model Swallow. Now, I am making EuropeanSwallow(Swallow) and AfricanSwallow(Swallow). I want to take some but not all Swallow objects make them either EuropeanSwallow or AfricanSwall...
I am building a small app that looks at availability of vehicles and helps a customer book it.
in this I am making use of a form wizard that guides the user through the steps.
in the backend I am updating all the queries successfully, however I am not quite sure on how to execute one part of it.
I have two models, Quote and Vehicle
V...
I have two models and one admin model:
class Person(models.Model):
firstname = models.CharField(maxlength=50)
surname = models.CharField(maxlength=50)
class Friends(models.Model):
person1 = models.ForeignKey("Person")
person2 = models.ForeignKey("Person")
friendship_made = models.DateField()
class PersonAdmin(adm...
Hi all,
Our product model can have multiple campaigns. Our customers change these campaigns frequently and generally on multiple products. So what we need right now seems that we need to show a multiple select widget on a change-list of Product model where our customers can easily change the campaigns.
Any idea on this? Maybe another...
Is there any problem with the syntax in the following code,there is a error as
Invalid block tag: 'else'
{%ifequal chat_profile 1 %}
{% extends "chatprofile/chat_profile1.html" %}
{% else %}
{% extends "chatprofile/chat_profile.html" %}
{% endif %}
...
Hi,
I understand that in Django, the ORM doesn't support the ENUM type in MySQL or PostgreSQL, as this was originally a MySQL extension, and not portable across other DB types. So the two options are to use a "choices" argument to your model, or using a foreign key reference.
What are the pros and cons of these approaches?
For somethi...
I'd like to do the following:
for table in table_list:
'table'.samefield = newvalue
...
What would be the correct statements for the below two.I want to send the base variable to my template which keeps varying but there will be an error if i send {'form': form,'msg' : msg} in the second statement
return render_to_response('chatlist/newchat.html', context_instance=RequestContext(request,{'form': form,'msg' : msg}),extra_co...
Hi,
I have a model with 100 or so entries - the client would like these entries to appear in a 'random' order, but would also like paging in there.
def my_view(request):
object_list = Object.objects.all().order_by('?')
paginator = Paginator(object_list, 10)
page = 1 # or whatever page we have
display_list = paginator.page(page)...