from django.db.models import Sum, DecimalField
from django.db.models.functions import Cast
Model.objects.annotate(deci_con_factor=Cast('conversion_factor',
DecimalField()).aggregate(sum=Sum('deci_con_factor')).get('sum')
You need to change your char type to decimal type , you can use CAST
opera
Hello,
i think this is the right answer:
from django.db.models import Sum
ModelName.objects.filter(field_name__isnull=True).aggregate(Sum('field_name'))#
returns {'field_name__sum': 1000} for example
Am So., 13. Juni 2021 um 12:04 Uhr schrieb www.forum-gh.com <
ladamo...@gmail.com>:
> Hello f
In case anyone else ends up here, I've found that it's very sensitive to
how you specify the Decimal, so in my example Decimal('20.00') worked but
Decimal('20') and Decimal(20) did not.
On Monday, April 20, 2015 at 6:44:30 PM UTC+1, eltonplima wrote:
>
> In the model below, using the Django admi
Use in the first line
#- coding: utf-8
from __future__ import unicode_literals
And put in models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class MyClass(object):
def __str__(self):
return "Instance of my class"
See more in
https://d
Python 3 have a better support of international alphabet.
2016-06-20 23:44 GMT+02:00 Xristos Xristoou :
> hello i want to use choices in my field but not work if i write in my
> language(greek) only work in the england language.
> if i writing choices in my language show me error message in the ad
On Mon, Apr 20, 2015 at 9:45 PM, Vijay Khemlani wrote:
> Overwrite the constructor of the form (__init__), pass the user or whatever
> parameters you may need and overwrite the choices of the field in the body
> of the method.
This is the same strategy I've used to filter ForeignKey fields on the
Overwrite the constructor of the form (__init__), pass the user or whatever
parameters you may need and overwrite the choices of the field in the body
of the method.
On Mon, Apr 20, 2015 at 10:56 PM, Steve Hiemstra
wrote:
> I am trying to build a form with dynamic choices. e.g., the choices shou
Hallöchen!
Todd Wilson writes:
> [...]
>
> [...] Instead of hard-coding the entity types here, you are using
> a constant, presumably because you may want to introduce more
> entity types later. But what are the trade-offs bewteen
> representing types as CharFields with choices, as you are doin
On Tue, May 11, 2010 at 4:11 PM, Preston Holmes wrote:
> Now I can think of several ways to do this in a form field init, but
> it seems like there should be a more reusable way to do it with a
> custom field type or mixin by overriding get_choices on the field
> object.
There is an easy way -- a
hi copy de code in first line your models.py or views.py
# -*- coding: UTF-8 -*-
bye :)
On Thu, Feb 18, 2010 at 7:55 PM, Karen Tracey wrote:
> On Thu, Feb 18, 2010 at 11:18 AM, hooda_28 wrote:
>
>> hi im having a problem for about an hour now, i have a model
>>
>> class Dummy(models.Model):
On Thu, Feb 18, 2010 at 11:18 AM, hooda_28 wrote:
> hi im having a problem for about an hour now, i have a model
>
> class Dummy(models.Model):
>sell = models.CharField(max_length=20, choices=Z_CHOICES)
>
>def __unicode__(self):
>return u'%s' % (self.sell)
>
> where Z_CHOICES =('9
yes its all working fine, when i change may choices like for example
Z_CHOICES =(('9','nnn'),('10','na',),) without any non-ascii character the
select box were shown with the choices list.
On Fri, Feb 19, 2010 at 2:56 AM, Timothy Kinney wrote:
> Can you successfully log in to the admin site using
Can you successfully log in to the admin site using the test server?
On Thu, Feb 18, 2010 at 10:18 AM, hooda_28 wrote:
> hi im having a problem for about an hour now, i have a model
>
> class Dummy(models.Model):
>sell = models.CharField(max_length=20, choices=Z_CHOICES)
>
>def __unicode
Oh sorry, thought you wanted multiple categories per photo. Tim's
response above is good.
As he said, I'd go with the ForeignKey approach, this makes the
categories easier to manage and gives you further flexibility of
storing additional information within each category (if you want).
Also his ex
For something like categories, I would go with a separate model and
use ForeignKey. For that 1% chance when you have to add a new
category, it will be a lot easier. Plus, what if requirements change
in the future and you are adding/deleting categories more than you
anticipated?
Using choices with
Hello Peter,
sorry, I was talking about choices, not a choice field:
http://docs.djangoproject.com/en/dev/ref/models/fields/#choices
Since any photo can only belong to one category (because I say so :) I
would tend towards using 1:N instead of M:N. Or did I missunderstand
you? If one photo can b
Hey Léon,
ChoiceField is a form field, not a table column—maybe you're thinking
about CommaSeparatedIntegerField? You could use that and hardcode
which categories represent which ids in your python code.
http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield
On the ot
Karen,
Thank you.
Based on your answer, I continued looking for problems in my code and
in my setup.
Firstly, the strings in the values of the choices were of length 7 and
the CharField was of length 6. I was helped by a coworker to fix that.
Then the problem of not showing the save'd choice pe
On Thu, Oct 16, 2008 at 1:43 AM, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
>
> hi,
>
> When I instance a ModelForm with a record of its base model, there is
> a CharField with "choices" that doesn't show the stored value in the
> combobox. Is this expected behaviour?
>
No. Details of your mo
On Jul 3, 8:13 am, urukay <[EMAIL PROTECTED]> wrote:
> no, no i mean it otherway, just like Rajesh Dhawan wrote (link he sent).
I will rephrase your original question; it's not obvious to everyone
that the REASON you want two of your six choices to be "not
selectable" is because they are CATEGORI
no, no i mean it otherway, just like Rajesh Dhawan wrote (link he sent).
guess i'll have to find other way to that, not in Model level.
but thanks
Alessandro Ronchi-2 wrote:
>
> 2008/7/3, urukay <[EMAIL PROTECTED]>:
>>
>>
>> yes, but it's only for limpidity :) and I need the user to chose
2008/7/3, urukay <[EMAIL PROTECTED]>:
>
>
> yes, but it's only for limpidity :) and I need the user to chose only one
> option from the list. Just can't count on that user wil chose to fill only
> one field with choices if there are more possible fields with choices.
> And it isn't possible to
yes, but it's only for limpidity :) and I need the user to chose only one
option from the list. Just can't count on that user wil chose to fill only
one field with choices if there are more possible fields with choices.
And it isn't possible to add to oe field multiple choices lists (i mena
some
On Wed, 2008-07-02 at 13:40 -0700, urukay wrote:
>
> is there a way how to create choices in Models in specific way, that some
> choices are not selectable (they only group and describe choices below)?
>
> e.g.:
>
> CHOICES = (
> ('0', 'Basic Colors'),
> ('1', 'Red'),
> ('2', 'G
thanks, but i was wondering if it's possible to do that in MODEL?
Rajesh Dhawan wrote:
>
>
>
>
> On Jul 2, 4:40 pm, urukay <[EMAIL PROTECTED]> wrote:
>> is there a way how to create choices in Models in specific way, that some
>> choices are not selectable (they only group and describe choic
On Jul 2, 4:40 pm, urukay <[EMAIL PROTECTED]> wrote:
> is there a way how to create choices in Models in specific way, that some
> choices are not selectable (they only group and describe choices below)?
>
> e.g.:
>
> CHOICES = (
> ('0', 'Basic Colors'),
> ('1', 'Red'),
> ('2', 'G
On Dec 8, 11:40 pm, Andreas Pfrengle <[EMAIL PROTECTED]> wrote:
> Hello group,
>
> I wanna use the admin interface for manipulating the db-data. I have a
> hierarchy of categories and products that shall belong to one or more
> categories. Here are the models I currently have:
> class Category(mod
On Dec 8, 11:40 pm, Andreas Pfrengle <[EMAIL PROTECTED]> wrote:
> Hello group,
>
> I wanna use the admin interface for manipulating the db-data. I have a
> hierarchy of categories and products that shall belong to one or more
> categories. Here are the models I currently have:
> class Category(mod
Seems like you'd want a many-to-many relationship, no?
Each student gets multiple teachers, and each teacher has multiple
students, unless all my years in school were for nothing :).
Or am I missing something?
Does delete remove FK's with M2M?
J
On Dec 17, 4:05 pm, radioflyer <[EMAIL PROTECTE
On Dec 17, 2007 7:05 PM, radioflyer <[EMAIL PROTECTED]> wrote:
> I have a Student model with a Foreign Key relationship to Teacher.
> When a teacher is removed, so go the students. Too dangerous for my
> particular scenario. There doesn't seem to be a Django feature that
> allows for adjusting the
radioflyer wrote:
> So the recommendation seems to be when your selection choices are not
> static you should go ahead and use a Foreign Key relationship. You get
> the automatic loading of the table into a select widget etc.
>
> But there's this issue of the cascade on delete.
>
> I have a Stud
I have read quickly the article "Variable Choice Lists'. I don't have
a lot experience with Django, however I would try to explain my case.
I have a model in which one of the fields has to be 'SelectedField',
therefore I have to use a 'choices' options.
class Dataset(models.Model):
.
.
On Tue, 2007-11-20 at 00:19 -0800, Nader wrote:
> Hallo,
>
> I have a model in which I have to use a input-field with choices
> option.
>
> ACCESS = (
> ('RO', 'readonly'),
> ('WO', 'writeonly'),
> ('RW', 'readwrite'),
> )
>
> Class myClass (...)
>..
>...
>activ
I am also struck on this...
I need output as
Select your gender
Male
Female
we are waiting for your valuable comments
cschand
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to th
hmm, replying to myself again because i can't wrap my head around it.
i drilled down to the boolean include_blank (which in turn seems to add
or not add BLANK_CHOICE_DASH) but that's only found in
db/models/fields/__init__.py and the magic that actually
decides whether the dash option is added or
Thanks for the pointer.
This does indeed change the default value to 'Male'
but the select-box still offers the dashes...
I want to eliminate the dashes-option completely,
why give the user a choice that will never be accepted?
-mark
On Mon, 2007-09-10 at 06:47 +, Ryan wrote:
> Use initial
Hi Amit,
thanks for your reply. This is how I do it now, but it requires to
assign all choices from model definitions to template. I would like to
have this list automatically assigned in the object. I don't know how
it should work, my idea is
{% for choice in item.get_status_choices %}
{{ choic
Assuming your choices type is defined as:
LANGUAGES = (
('he', 'Hebrew'),
('en', 'English'),
)
You have to pass it through the context, and then you can access the list as
follows:
{% for lang in LANGUAGES %}
{{ lang.0 }} {{ lang.1 }}
{% endfor %}
Hope this helps,
--- Amit
ב
Use initial when calling your form class.
formClass = forms.form_for_model(Person)
form = formClass(initial={'gender': 'm'})
On Sep 6, 4:31 pm, Mark Green <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> This is my model:
>
> class Person(models.Model):
> GENDER_CHOICES = (
> ( 'm', 'Male' )
On 30-Aug-07, at 1:29 PM, Michael Radziej wrote:
>>
>> True, that's why I call this behaviour "buggy".
>
> Ah! I thought that you advocated for gettext instead of
> gettext_lazy in this
> specific situation.
well, i am using gettext until the bug is fixed - so far no problems
--
regards
kg
On Thu, Aug 30, Jarek Zgoda wrote:
>
> Michael Radziej napisał(a):
>
> The next testing option is to try with non-lazy version.
> >>> that works! import gettext as _
> >> And that's a real bug, I think.
> >>
> >> Anyway, for future reference, keep in mind that lazily translated
> >> "strin
Michael Radziej napisał(a):
The next testing option is to try with non-lazy version.
>>> that works! import gettext as _
>> And that's a real bug, I think.
>>
>> Anyway, for future reference, keep in mind that lazily translated
>> "strings" become real strings at access time. Before that the
On Wed, Aug 29, Jarek Zgoda wrote:
>
> Kenneth Gonsalves napisał(a):
>
> >>> now, this doesnt work - when I remove the _(), then the choices
> >>> appear. How do I then mark them for translation?
> >>>
> >> Make sure to use gettext_lazy
> > i *am* using: from django.utils.tr
Kenneth Gonsalves napisał(a):
>>> now, this doesnt work - when I remove the _(), then the choices
>>> appear. How do I then mark them for translation?
>>>
>> Make sure to use gettext_lazy
> i *am* using: from django.utils.translation import gettext_lazy
> as _
Ha! H
On 29-Aug-07, at 2:53 PM, Jarek Zgoda wrote:
>> now, this doesnt work - when I remove the _(), then the choices
>> appear. How do I then mark them for translation?
>>
> Make sure to use gettext_lazy
i *am* using: from django.utils.translation import gettext_lazy
as _
On 29-Aug-07, at 2:51 PM, Michael Radziej wrote:
>> doesnt work - i just marked one string, the marked string didnt
>> appear, the other two did.
>
> Well, sorry, then I'm personally running out of ideas. But this
> looks really
> weird.
i filed a bug report
--
regards
kg
http://lawgon.liv
Kenneth Gonsalves napisał(a):
> now, this doesnt work - when I remove the _(), then the choices
> appear. How do I then mark them for translation?
>
Make sure to use gettext_lazy
>>> i *am* using: from django.utils.translation import gettext_lazy as _
>> Ha! How should we know?
>
On Wed, Aug 29, Kenneth Gonsalves wrote:
>
>
> On 29-Aug-07, at 2:24 PM, Michael Radziej wrote:
>
> now, this doesnt work - when I remove the _(), then the choices
> appear. How do I then mark them for translation?
>
> >>>
> >>> Make sure to use gettext_lazy
> >>
> >> i *am* usi
On 29-Aug-07, at 2:24 PM, Michael Radziej wrote:
now, this doesnt work - when I remove the _(), then the choices
appear. How do I then mark them for translation?
>>>
>>> Make sure to use gettext_lazy
>>
>> i *am* using: from django.utils.translation import gettext_lazy as _
>
> Ha
On Wed, Aug 29, Kenneth Gonsalves wrote:
>
>
> On 28-Aug-07, at 9:55 PM, Chris Hoeppner wrote:
>
> >> when i upgraded to the latest svn head, I found that all the places
> >> in admin that had drop downs for choices were blank. I had always
> >> marked my choices for translation like so:
> >>
On 28-Aug-07, at 9:55 PM, Chris Hoeppner wrote:
>> when i upgraded to the latest svn head, I found that all the places
>> in admin that had drop downs for choices were blank. I had always
>> marked my choices for translation like so:
>>
>> article_type = (
>> ("NW", _("News")),
>> ("FT",_("Featu
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Kenneth Gonsalves escribió:
> hi,
>
> when i upgraded to the latest svn head, I found that all the places
> in admin that had drop downs for choices were blank. I had always
> marked my choices for translation like so:
>
> article_type = (
> ("NW
Many thanks, that sorted it.
Interesting to note that using the string format the data still got
stored in the Database and was getting displayed back in the admin
detailed view, but not in the list view.
MerMer
--~--~-~--~~~---~--~~
You received this message be
>
> RATING_CHOICES=(
> ('5', '5 stars'),
> ('4', '4 stars'),
> ('3', '3 stars'),
> ('2', '1 stars'),
> ('1', '1 star'),
> )
Replace the first element of each tuple with an integer as you are
feeding it to an IntegerField. Li
On Oct 6, 2006, at 2:20 PM, MerMer wrote:
>
> Ray,
>
> The code is below. The RATINGS_CHOICES are defined inside the Model
> Class.
>
> MerMer
>
> RATING_CHOICES=(
> ('5', '5 stars'),
> ('4', '4 stars'),
> ('3', '3 stars'),
> ('2', '1 stars'),
>
Ray,
The code is below. The RATINGS_CHOICES are defined inside the Model
Class.
MerMer
RATING_CHOICES=(
('5', '5 stars'),
('4', '4 stars'),
('3', '3 stars'),
('2', '1 stars'),
('1', '1 star'),
)
rating=models.Intege
Hi,
Can you copy the definition of your RATING_CHOICES? Also, where is it
defined in your models file?
-Raj
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email t
Thanks Adrian for your quick answer,
I should have mentioned that I was aware of the FilePathField and have
played around with it. the reason I cannot use it is that I want to
display a list of _directories_ and not _files_
unfortunately I wasnt able to make FilePathField give me a list of
direct
On 4/14/06, frank h. <[EMAIL PROTECTED]> wrote:
> one field in my model is a "directory" field. I present the user with a
> choice of directories on the local filesystem in the admin app.
> Basically
>
> infolder = meta.CharField('Video infolder', maxlength=250,
> choices=getDirs())
>
> with a cus
On Mar 27, 2006, at 10:13 PM, Max Battcher wrote:
> If you visit the Admin's documentation site (link in the top bar),
> under
> Models it will point you to the fact that Django magically creates a
> function for you to do just that. In your example this would be:
>
> something.get_kind_display
Todd O'Bryan wrote:
> I'm an almost complete Python newbie, and I found dictionaries, but
> is there an automatic way to deal with lists of pairs that have been
> used for choices settings in the admin view, cause they're tuples of
> tuples, right?
>
> I have
>
> KINDS = ((0, 'foo'), (1, '
Hi rob, thanks for your info. I tried NullBoleanField as you said one
month ago but without any success (see my post of Oct 28th). Now I'm
trying again and IT WORKS :) . This is a working example, related to my
problem:
choice = meta.NullBooleanField("Null Boolean", choices=((True,"It's
true"),(Fa
Hi Emanuele,
To force a user to make a choice wrt boolean fields, you have two
options: a BooleanField or (as you seem to be looking for) a
NullBooleanField, which actually represents three states (including
'unselected'). This will mirror what you are trying to achieve with the
CharField solution
Thanks for the answer Adrian. But let me say this:
- BooleanFields _are_ currently allowed to have "choices" parameter, as
I can see from my admin interface and docs (svn ~ rev1580). And they
behave differently from other Fields.
- Boolean has obviously only two choices, but if I want to force th
On 12/8/05, Emanuele <[EMAIL PROTECTED]> wrote:
> BooleanFields behaves differently in admin interface: the field name
> name ("Boolean") is not in bold style (not mandatory?) and if you
> select the first choice ("You can't select this", as before) you get an
> error because there is no validatio
On 8/29/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> my_print = Print(paper_type=1)
> print my_print.paper_type
>
> will print out 1. Is there a recommended pattern for printing out
> "Letter"?
Generally this is the pattern we've used in our own code:
"""
class Print(meta.Model):
pape
Is there a recommended approach to displaying the choice text rather
than integer?
for instance:
my_print = Print(paper_type=1)
print my_print.paper_type
will print out 1. Is there a recommended pattern for printing out
"Letter"?
I have been doing methods using a dict that I use to create the
On 8/26/05, Maniac <[EMAIL PROTECTED]> wrote:
> What should I consider when choosing between them? I suppose choices
> tuple is easier to work with when making views since Django
> automatically generates for it (or am I wrong here?). On the
> other hand lookup table is more flexible since I can
68 matches
Mail list logo