The label_from_instance should simply return the obj. I don't think any
fuzzy codes is needed as
described in the Django docs [1]
The method label_from_instance already converts the objects to string. So a
simple override like this:
class MyModelChoiceField(ModelChoiceField):
def label_from_i
I have made changes like this:
""" Introduced a new model to store the form field select values """
class Branch(models.Model):
"""Branch"""
name = models.CharField(max_length=50)
name_branch = models.CharField(max_length=50)
address_1 = models.CharField(max_length=100)
class
On Mon, Aug 8, 2011 at 2:56 PM, Daniel Roseman wrote:
>
> I'm afraid it's really not clear what you're trying to do, or what the
> problem is.
> If the issue is that you have a field referring to a foreign key, and you
> want to change what the values displayed in the dropdown for that field,
> th
On Monday, 8 August 2011 13:06:51 UTC+1, Kayode Odeyemi wrote:
>
> That didn't help either. It still did not depict what I'm trying to do.
> Those filters are for retrieving values set by a user. However, I tried the
> code below which is to hard code the choices into the form field on creation
Yeah form.branch_name displayed but the values are not the tuples - this is
the primary reason why I'm seeking for help.
I have dabbled into the modelForm (widgets) as an option, obviously no luck
there.
At the moment, I'm building a new model that maps the db table that contains
the values, buil
Like they do in the admin, right ?
You might want to check Django's source for the admin forms and templates to
get some inspiration then.
Hard coding the choices is never a satisfactory solution but I suggest you
retrieve them from your models file so you stay DRY compliant and then it's
pretty
That didn't help either. It still did not depict what I'm trying to do.
Those filters are for retrieving values set by a user. However, I tried the
code below which is to hard code the choices into the form field on creation
class TransactionUpdateForm(forms.ModelForm):
branch_name_new = forms
Oh, sorry, I must have misunderstood then.
I remember reading a post on thread on SO that addressed this, and I believe
that they came up with a template filter as there was no "simple" way to do
it.
Here it is:
http://stackoverflow.com/questions/1105638/django-templates-verbose-version-of-a-choi
Thanks for the reply.
I have a views.py like this:
@login_required
def update_transaction(request, tpin=None):
qs = Q(my_institution=None) |
Q(my_institution=request.user.get_profile().my_institution)
txn = get_object_or_404(Transaction.objects.filter(qs), tpin=tpin)
context = {'page_
Check out get_FOO_display, there:
https://docs.djangoproject.com/en/dev/ref/models/instances/
Le 8 août 2011 11:06, "Kayode Odeyemi" a écrit :
> In the Django [1], the example as described below shows how to build Forms
> that are tied to a model.
>
> from django.db import models
> from django.for
10 matches
Mail list logo