Okay my Model now looks like this:

class Produkte(models.Model):
    Kategorie = models.ForeignKey(Kategorien)
    Titel = models.CharField(max_length=100)
    Auflage = models.IntegerField(max_length=2, default=0)
    Bestell_Nr = models.CharField(max_length=30, blank=True)
    ISBN = models.CharField(max_length=30, blank=True)    
    Autor = models.CharField(max_length=50, blank=True)
    Status = models.IntegerField(max_length=1, blank=False, default=1)
    
    def __unicode__(self):
        if self.Auflage:
            return "%s %s" % (self.Titel, self.Auflage)
        else:
            return self.Titel
    
    class Meta:
        db_table = 'tb_Produkte'
        verbose_name_plural = "Produkte"
        verbose_name = "Produkt"
        unique_together = ("Kategorie", "Titel", "Auflage", "Status")
    
    class ModelChoiceField(ModelChoiceField):
        def label_from_instance(self, obj):
            return "%s%i" % obj.Titel, obj.Auflage

but that didn't really change anything :-(


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: 00431 534521573 
Fax: +43 (1) 534 52 - 146 


-----Ursprüngliche Nachricht-----

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von Tom Evans
Gesendet: Montag, 04. Juli 2011 12:19
An: django-users@googlegroups.com
Betreff: Re: change values in "select list"

On Mon, Jul 4, 2011 at 11:12 AM, Szabo, Patrick (LNG-VIE)
<patrick.sz...@lexisnexis.at> wrote:
> Hi,
>
>
>
> I have a forum that looks like this:
>
>
>
> class ReportingForm_Produkt(ModelForm):
>
>     class Meta:
>
>         model = Buchung
>
>
>
> Where Buchung and Produkt looks like this:
>
>
>
> class Buchung(models.Model):
>
>     Mitarbeiter = models.IntegerField(max_length=3)
>
>     Produkt = models.ForeignKey(Produkte)
>
>     Datum = models.DateField()
>
>     Aktivitaet = models.ForeignKey(Aktivitaeten, blank=True)
>
>     Minuten = models.PositiveIntegerField(max_length=2)
>
>
>
>     def __unicode__(self):
>
>         return str(self.Mitarbeiter) + ' ' + str(self.Datum)
>
>
>
>     class Meta:
>
>         db_table = 'tb_Times'
>
>         verbose_name_plural = "Buchungen"
>
>         verbose_name = "Buchung"
>
>
>
> class Produkte(models.Model):
>
>     Kategorie = models.ForeignKey(Kategorien)
>
>     Titel = models.CharField(max_length=100)
>
>     Auflage = models.IntegerField(max_length=2, default=0)
>
>     Bestell_Nr = models.CharField(max_length=30, blank=True)
>
>     ISBN = models.CharField(max_length=30, blank=True)
>
>     Autor = models.CharField(max_length=50, blank=True)
>
>     Status = models.IntegerField(max_length=1, blank=False, default=1)
>
>
>
>     def __unicode__(self):
>
>         if self.Auflage:
>
>             return "%s %s" % (self.Titel, self.Auflage)
>
>         else:
>
>             return self.Titel
>
>
>
>     class Meta:
>
>         db_table = 'tb_Produkte'
>
>         verbose_name_plural = "Produkte"
>
>         verbose_name = "Produkt"
>
>         unique_together = ("Kategorie", "Titel", "Auflage", "Status")
>
>
>
> Now if i include that form into a template, the dropdown only shows the
> "Titel" of each objects from "Produkte".  I also want the "Auflage" - Info
> to be visible in the drop down.
>
>
>
> How do i do that ?!
>
>
>
> greetings
>


https://docs.djangoproject.com/en/1.3/ref/forms/fields/#modelchoicefield

"""
The __unicode__ method of the model will be called to generate string
representations of the objects for use in the field's choices; to
provide customized representations, subclass ModelChoiceField and
override label_from_instance.
"""

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to