On May 18, 7:57 am, Alexandre González wrote:
> But don't you think that have attributes that I don't need is a perfomance
> lost? I only ask, I'm learning django :)
>
> I go to see the documentation that you send me, thanks for your help.
There will be a minuscule amount of
On May 18, 12:39 am, rahul jain wrote:
> Awesome job...but I discovered just one problem. Select all missing from
> admin panel. So now i cannot select all the objects if i want to from admin
> panel. It was fine on django 1.1. Its not fine on django 1.2 nor in the
>
> annotate(myorder=Max('product__datefield')).order_by('producer.id',
> 'myorder')
Sorry, flip the order_by arguments:
.order_by('myorder', 'producer.id')
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email
> but I have to order this "structure" by the date of added product
> ( newer first ) so if I add to this : product 2 for Producer 3 it
> should look like this :
>
> Producer 3
> product 1
> product 2
> Producer 1
> product 1
> product 2
> Producer 2
> product 1
>
> so, is it possible to do
> Voila, I now have created an app that is independent of it's
> surrounding project. The only thing left is the fact that my app has
> templates, which I understand is a no-no when making reusable apps.
> I'll start working on that later, as I'm satisfied now with no strict
> backwards
On May 13, 6:48 pm, Bill Freeman wrote:
> Or you could be right. I'm still not clear on the OP's intent.
I suspect both would work, with my solution relying on a queryset
containing a single object. Yours is cleaner!
Regards
Scott
--
You received this message because you
> When I try to run syncdb, manage.py returns an error saying that my
> app (djangoapp) could not be found. I've tried to add the URL of the
> app to the system path so that it would be accessible from external
> directories - to do this I've tried adding the absolute URL of my app
> to my
Righto -- unfortunately that's the best solution I've come up with to
date. Here's the detailed version:
# models.py
def get_upload_path(instance, filename):
return "%s/%s/%s" % (instance.__class__.__name__.lower(),
instance.uuid, filename,)
def get_uuid():
import uuid
return
m an itterator I'll call 'd.items()':
>
> user = User.objects.get(id=11)
> for key, value in d.items():
> setattr(user, key, value)
> user.save()
>
>
>
>
>
> On Thu, May 13, 2010 at 2:10 PM, zinckiwi <zinck...@gmail.com> wrote:
> >> What if field
> What if field_name and value coming from loop?
> I have around 50 field and values in loop.
> Can I do this? I know this is silly way to do but please guide how can
> I do this?
>
> for key, value in users:
> user."%s" = "%s" % (key, value)
>
> user.save()
Ah, I see. In that case you will
> I am little confused about it. I am not sure django allow this or not.
> Please correct me.
>
> string = last_name = 'Riaz edit', first_name = 'Asim edit',
> nationality = 'se'
> User.objects.filter(id=11).update(string)
>
> I am using this and its giving me this error:
>
> update() takes
> I have overriden the save method on my model, and want to use the id
> field (default autoincrementing pk) to set one of the other fields.
>
> Is this ok:
>
> class MyModel(models.Model):
> ...
> def save(self, *args, **kwargs):
> super(MyModel, self).save(*args, **kwargs)
>
Not the prettiest thing in the world, but there's always:
header
{% if var1 %}{{ ... }}
{% endif %}{% if var2 %}{{ ... }}
{% endif %}{% if var3 %}{{ ... }}
{% endif %}
footer
Regards
Scott
On May 12, 2:20 pm, Noah Watkins wrote:
> Peter
>
> I don't believe
Change your "datetime.now()"s in your manager to "datetime.now"s. The
callable version will be called every time, rather than only once at
the start of the process.
Regards
Scott
On May 11, 2:08 pm, Malcolm Box wrote:
> Hi,
>
> I've run into a weird bug that has me
Write yourself a context processor and register it in your
settings.TEMPLATE_CONTEXT_PROCESSORS. For example, registering
myapp.context_processors.template_defaults:
# myapp/context_processors.py
def template_defaults(request):
return {
"BASE_TEMPLATE": "base/base.html",
Are you asking about factoring out certain common functionality shared
between models? It's quite common; for example most of my projects
have something like this as a starting point for many models:
class DatestampedModel(models.Model):
created =
> my HTML form tag is as follows:
>
>
>
> How can I avoid losing the "?token=blah" part? I think this could be
> the problem.
You'll want to replace it with this:
As explained here:
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.get_full_path
> > assert
First thing would be to ensure that when you submit the form back to
itself, the querystring remains. It's all well and good to visit a
form like this:
/someapp/myform/?token=blah
But if your HTML form tag is:
Then you'll lose the "?token=blah" part when you submit.
Other than that, nothing
> The actual call I had tried was
> Payment.objects.filter(appliedpayment__invoice__location=loc).distinct().ag
> gregate(Sum('amount'))
> (where amount is a field on Payment). I could do
> AppliedPayment...aggregate(...), but unfortunately the AppliedPayment
> splits the 'amount' into several
I'd try both and compare the processing time. What is the nature of
the Beta.name equivalent in your actual model? If it is a simple field
(e.g. INT) I doubt the overhead would be too bad. What might be
tripping me up is having your Gamma being linked to your Alpha through
an intermediate model.
> In [29]:
> Alpha.objects.filter(gamma__beta__name='Beta').values('id').aggregate(model
> s.Sum('id'))
> Out[29]: {}
>
> In [30]:
> Alpha.objects.filter(gamma__beta__name='Beta').values('name').aggregate(mod
> els.Sum('id'))
> Out[30]: {}
That's odd -- I would have expected #29 to work (though
On May 4, 9:49 am, Sander wrote:
> I don't want to check if if_active = True
> I wan't to check if if_active is changed to True
If you use the pre_save signal, you can get the object as it currently
exists (based in the signalled instance's pk) and compare the
> In [16]:
> Alpha.objects.filter(gamma__beta__name='Beta').aggregate(models.Sum('id'))
> Out[16]: {'id__sum': 2}
>
> In [17]:
> Alpha.objects.filter(gamma__beta__name='Beta').distinct().aggregate(models.
> Sum('id'))
> Out[17]: {'id__sum': 2}
>
> As you can see, the aggregate call in 17 ignores
> Very few of the fields in my models are required (in real life). But
> the default attribute for a django field is that it is required.
>
> http://docs.djangoproject.com/en/1.1/ref/models/fields/#django.db.mod...
>
> Is there a way to toggle that, globally, so that I can just make the
> few
Finding it a wee bit hard to follow without actual models. Could you
post them?
> I guess I'm writing this to confirm a behaviour and see if there might
> be a work around.
>
> It appears that qs.aggregate(Sum('field')) ignores qs.distinct().
>
> If I have something like this:
>
> qs =
> 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
> If your fixture only contains B objects, then importing will fail if
> the A objects they're keyed to don't exist. Test databases are blank
> aside from fixtures, so the test DB and blank DB are telling you the
> same thing. You'll need to ensure that you have fixtures not only for
> the models
Your fixture probably contains objects whose model(s) contain foreign
keys to other objects.
class A(models.Model):
pass
class B(models.Model):
a = models.ForeignKey(A)
If your fixture only contains B objects, then importing will fail if
the A objects they're keyed to don't exist. Test
> class Pubblicazioni(models.Model):
> anno = models.DateField(blank=True, null=True,default=datetime.date.today)
> autori = models.CharField(max_length=500)
> titolo = models.CharField(max_length=500)
> autori_daf = models.ManyToManyField(User)
>
> I need to ordering (by the
> class Account(models.Model):
> name = CharField
>
> class Entry(models.Model):
> account = ForeignKey(Account)
>
> class Page(Entry):
> name = CharField
>
> There's my simple example. I want to get all pages that belong to
> Account. account.page_set.all() does not relate, and I can
> I need to filter a field by a UserProfile function, i.e. how can I do
> something like this?
>
> class Paquet(models.Model):
> ...
> profiles = models.ManyToManyField(UserProfile, limit_choices_to =
> {'country': request.user.userprofile.country})
I'd put that restriction inside the
Hi all,
I have a custom inclusion tag that renders a template filled with
topical data for use in a sidebar. This is used on many pages, but not
all, and has some supporting javascript and CSS. Currently all that
lives in the tag's template, (incorrectly) inline with the html:
...
...
I
Hi folks,
I have a seemingly straightforward problem but can't figure out a way
to do it natively in the ORM. I have two models:
class Puzzle(models.Model):
name = models.CharField(max_length=50)
class Result(models.Model):
user = models.ForeignKey(User)
puzzle =
Hi folks,
Let's say I have an app called "Attributes" that holds flags for user
account modifiers (e.g. "TurnOffAds"). So I might have a model inside
this app to contain all the available attributes:
class Attribute(models.Model):
name = models.CharField(max_length=50)
Thanks Malcolm.
> Define "didn't seem to work"?
> ...
> Have a look in django/templates/defaulttags.py for examples of argument
> parsing in the built in tags for Django.
I'm sure it was a gap in my knowledge, since you're obviously right
about the built-in tags. I'll take a look at them. I was
Hi All,
I have a couple of views in my project that process two forms at once
(that is, two django forms; one HTML form of course). While I maintain
the User and UserProfile models separately, for UI purposes they are
one construct, so I have an "Edit Account" page that uses a user_form
and a
Hi folks,
I'm just starting to play with django-registration and I want to
subclass the RegistrationForm for a couple of cosmetic tweaks
(capitalising the labels on the fields -- there may be a simpler way
to do this, but indulge me for the purposes of this question). I
understand that
37 matches
Mail list logo