You would order them on the model level or on the view level. In the
model, you can set ordering with the Meta class 'ordering' parameter.
In the view, you would just add .order_by() to your query. Check out
these thinks:
http://docs.djangoproject.com/en/dev/ref/models/options/#ordering
http://do
Those *links! Hah.
On Apr 16, 12:08 pm, Nick Serra wrote:
> You would order them on the model level or on the view level. In the
> model, you can set ordering with the Meta class 'ordering' parameter.
> In the view, you would just add .order_by() to your query. Check out
>
Hey everyone, thanks for looking.
I'm overriding a model save(), and was wondering if there is an
instance of the model being passed in that i can access.
My situation is that i have a title and a slug. I only want to change
the slug when the title is changed. So in my save i want to check:
if s
Thank you, that seems like a clean way to do it. I'm getting a weird
error when overriding init though. When I simply do this:
class Entry(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)
body = models.TextField()
user
Ahh, that'll do it. I'm used to the save() where you call super last.
Works perfect, thanks for the solution!
On Apr 21, 1:19 pm, Shawn Milochik wrote:
> You should probably call that super __init__ first thing. Otherwise the
> object won't really know how to behave like a Django model.
>
> Shaw
I think i ran into this issue before. I don't think they define a
max_length anywhere, the restriction is just on the database. Just
increase the field size in the database and you should be good.
On Apr 21, 2:20 pm, Tom Evans wrote:
> On Wed, Apr 21, 2010 at 6:22 PM, CrabbyPete wrote:
> > Yes,
Just create a model that stores the url and the expiration time. If
the url is hit past the expiration time, delete it, if it's still
within the time limit, display whatever you want to display. Obviously
this is for a small system, since you would be waiting to delete until
the url is hit, but its
Request is an object that django passes view functions that includes
post data, meta data, and data about the request taking place. Not
sure what your test function is doing, but to start, python is
complaining because you are referencing the variable before it has
been declared. You need to define
Whenever I use django on my windows box, i use XAMPP, which is a all
in one installer that gets apache and mysql.
So I:
- install XAMPP
- install python
- svn checkout django in the site-packages folder
- install mysql bindings for python
- install python image library
and I think you need to add
A post save signal seems better suited for this. The post save signal
has an attribute 'created' that will be true or false depending on if
the object is being created or updated. Check out the post_save
documentation:
http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post
efined rather than
> auto-incrementing pk.
>
> On Apr 23, 4:21 pm, Nick Serra wrote:
>
>
>
>
>
> > A post save signal seems better suited for this. The post save signal
> > has an attribute 'created' that will be true or false depending on if
>
w, it increments TWICE!
>
> Is there some glaring error in my logic above?
>
> On Apr 23, 4:50 pm, Nick Serra wrote:
>
>
>
> > I didn't even think of that. It's not very common to be specifying
> > pk's on create anyway, so yours would probably
:)
On Apr 26, 9:48 am, Jim N wrote:
> Nick,
>
> Thanks very much. That worked! I can't work out why my code didn't
> though (or rather, worked twice).
>
> -Jim
>
> On Apr 23, 6:37 pm, Nick Serra wrote:
>
>
>
>
>
> > Try this out and see
There are a couple ways to do this. You can either override the model
methods like save and init, or you can use signals and tie into the
pre_save, post_save, etc. Signals are here:
http://docs.djangoproject.com/en/dev/ref/signals/
If using signals, you will have an instance of the object being s
Can you be more clear on the exact result you're trying to achieve? Do
you want to see, for a given high school, how many recruit objects are
foreign keyed to it?
On Apr 26, 7:38 am, Nuno Maltez wrote:
> Are you saying that:
>
> collegelist =
> college.current_objects.filter(collegechoices__scho
Seems very odd how you're trying to implement this. Unless your
pseudocode has me confused. Can you give us the view functions too?
Seems like you're trying to use a decorator function on two views. Why
don't you just bail on the decorator, and just check for
request.GET.get('format') == 'rss', and
Include request context:
from django.template import RequestContext
...and then pass it in with the render. That should include the token
in the template.
return render_to_response('add_pair.html', {},
context_instance=RequestContext(request))
On Apr 26, 12:45 pm, jeff wrote:
> so i have some
Interesting. If the file is an mp3, maybe try:
file = open("/path/to/my/song.mp3", "rb").read()
response['Content-Disposition'] = 'attachment; filename=filename.mp3'
return HttpResponse(file, mimetype="audio/mpeg")
On Apr 26, 1:20 pm, Dexter wrote:
> Hi there,
>
> I want to send an audio file v
You could create a model that references the join table itself.
class ArticlePublicationsJoin(models.Model):
id = models.AutoField()
publicaiton_id = models.IntegerField()
article_id = models.IntegerField()
class Meta:
db_table = 'article_publications'
then just query on
Are you trying to interface django with an existing table? Why do you
have the StandardCode class foreign key-ing to the table, instead of
just making a model that references the table exactly?
On Apr 26, 2:43 pm, Jesse wrote:
> Table LOINCCode has loinc_obr4 (a number) and a description field
>
Hey everyone. I'm trying to access the request object while overriding
the save or tapping into the post_save on a model. I need request info
when someone posts a comment. But I don't just want to handle this in
my view, I would like it to be cleaner than that, so that
functionality would remain ev
Hey, quick query question. I know there has to be an answer for this
one, just don't know the syntax. I need to follow the reverse
relationship for an extended model.
class Account(models.Model):
name = CharField
class Entry(models.Model):
account = ForeignKey(Account)
class Page(Entry):
Yeah, that is going to be my fallback, I was just curious on an actual
reverse relationship solution to the situation. Thanks for the input!
On Apr 28, 4:12 pm, zinckiwi wrote:
> > class Account(models.Model):
> > name = CharField
>
> > class Entry(models.Model):
> > account = ForeignKey(
Yeah, I realize this now hah. Instead I am now passing request into a
ModelForm for what I need. Basically I have a comment system, and on
each comment post I wanted to run it through Akismet, which required
the IP and User Agent. So I just passed request into my form.save()
method on comment adds.
I just implemented this and it's a hassle. There are heated
discussions about it. I ended up modifying the auth app and completely
eliminating the 'username' field and just using email. Then I modified
the admin app to allow the login, and am basically just completely
overriding both. Good luck!
O
Awesome! Thanks so much!
On May 6, 3:32 am, Federico Capoano wrote:
> I've been using the beta for a while and it works pretty good for what
> I've seen.
>
> On May 6, 6:40 am, James Bennett wrote:
>
>
>
>
>
> > Tonight we're proud to announce, finally, the first Django 1.2 release
> > candidate
Sorry for the confusing title. Here is a simple example to illustrate
my question:
class Item(models.Model):
name = models.CharField()
class Manager(models.Model):
item = models.ForeignKey(Item)
On a POST I have the PK of the Item I want to link to a new instance
of the Manager object.
Thanks for the response. I actually will already have the PK, and am
trying to avoid grabbing an instance of the actual item object.
On May 12, 11:26 am, Daniel Roseman wrote:
> On May 12, 4:04 pm, Nick Serra wrote:
>
>
>
>
>
> > Sorry for the confusing title. Her
Exactly what I was looking for, thanks!
On May 12, 11:50 am, Daniel Roseman wrote:
> On May 12, 4:34 pm, Nick Serra wrote:
>
> > Thanks for the response. I actually will already have the PK, and am
> > trying to avoid grabbing an instance of the actual item object.
>
>
You can go two directions with this. First, you could use a
intermediate model for the many to many join, which would allow you to
specify extra field on the join, in this case the order. Read up on
this here:
http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relat
Look into the clear() method on many to many relations.
Calling .clear() before a delete will remove all relations between the
models and allow you to delete the category only. You might be
fighting the django admin on this though, so this would be best
implemented in a custom solution. Not sure if
rap the many to many relationship. (there are lots of
> films that have multiple filmmakers and vice versa, and I'd like to be
> able to list them on both ends) I'm still trying to wrap my head
> around how I could do that with this example.
>
> If anyone has anything else
mple going, I guess I'll try the inline solution as well, if it's
> > the pretty way to do it... It'll be good for me to actually see what
> > they both do.
> > W
>
> > On Aug 16, 12:28 pm, Nick Serra wrote:
>
> > > The inline solution is th
gt; {% for filmmaker in filmmakers %}
> {% if filmmakers|length > 2 and not forloop.first
> %}, {% endif
> %}
> {% if forloop.last and not forloop.first %}and {%
> endif %}
> {{filmmake
trying to match the id.
>
> I'm going to read about filtering a little more, feels like it's
> close...
> (I also tried to put film_id in the parens after filter and got a "too
> many values" error.)
> So much to learn, thanks
You're just all around doing it wrong. A ModelForm is used so that you
don't have to individually list all the fields you need, it is based
off the model. What is the code for your Model? And also, I'd reread
the form reference from the start.
On Sep 26, 5:25 pm, Marc Aymerich wrote:
> On Sun, Se
Hey everyone, thanks for looking. I couldn't think of a good title for
this one. I have a question on queries on manytomany relations. Here
is an example:
class Item:
genre = models.ForeignKey(Genre)
class Genre:
name = models.CharField()
class Video:
genre = models.ManyToManyField(G
You could query like this:
Question.objects.filter(answer__isnull=False)
This would give you a set of questions where an answer exists. Setting
it to True would give you a set where answers don't exist.
On Apr 12, 12:20 pm, Jim N wrote:
> Just to clarify, I'm trying to filter questions that hav
l)
On Apr 12, 1:32 pm, Jim N wrote:
> Yes! That's it! Thank you.
>
> On Apr 12, 1:21 pm, Nick Serra wrote:
>
>
>
> > You could query like this:
>
> > Question.objects.filter(answer__isnull=False)
>
> > This would give you a set of questions where
ref/models/querysets/#in
>
> Item.objects.filter(genre__in=some_video.genre.all())
>
> On Apr 12, 10:03 am, Nick Serra wrote:
>
>
>
> > Hey everyone, thanks for looking. I couldn't think of a good title for
> > this one. I have a question on queries on
Hey everyone, thanks for looking. I am developing a site that has
spanish translations. I18n is working properly, but when I switch to
spanish, my form output that has dates is in spanish. This is a
problem because I am sending out staff emails on some forms, which
cannot have spanish in them. So I
That error just means you didn't add that field to the database and it
can't find it. Verify the user_id field is on that table.
On Jul 13, 2:40 pm, Petey wrote:
> Hi!
>
> I've made a model in news application:http://pastebin.com/49VkFT14
>
> I want it to save user who created a message, however
I'm too lazy to check, but i'm pretty sure the name of your file input
needs to match the name of the form field. Also, try troubleshooting.
Use print statements in the view to see if the file object is being
posted, etc.
On Dec 21, 11:54 pm, vivek_12315 wrote:
> Awaiting reply!
>
> On Dec 22, 3:
http://translate.google.com/#auto|en|%20list%20index%20out%20of%20range
On Dec 21, 6:10 pm, Bill Freeman wrote:
> On Tue, Dec 21, 2010 at 5:53 PM, Jonathan Hayward <
>
>
>
>
>
> christos.jonathan.hayw...@gmail.com> wrote:
> > [jhayw...@cmlnxbld01 invdb]$ python manage.py shell
> > Python 2.7 (r27
Could just put the group in the initial data for sync db. Look up
django fixtures. It will load data into the database from a json feed
on syncdb.
On Dec 21, 1:50 pm, "Mark (Nosrednakram)"
wrote:
> Hello,
>
> I would like to install an auth_group with my application and am
> considering using the
Hey everyone, thanks for looking.
Running into a problem getting the Django Admin working with a custom
auth system. Have everything working, but I cannot get the admin to
use my custom auth app to login. I am not running a custom auth
backend, but an entirely different auth app in my project. Bas
Andre's solution is out of date. Calvin is correct, use the user
profile model that is built into django auth. OP, the link you found
is correct.
On Mar 25, 11:39 am, Andre Terra wrote:
> This is the correct way:
>
> http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...
>
> Sin
47 matches
Mail list logo