samedi 23 avril 2016

Django database sqlite display of value of attribute

I'm on a project using django and I wrote my models.py

I have two classes

class Adresse(models.Model):
    numV=models.IntegerField(blank=False,null=False)
    complementdest=models.TextField(blank=False,null=False)
    complementadr=models.TextField(blank=False,null=False)
    commune=models.TextField(blank=False,null=False)
    codeP=models.IntegerField(blank=False,null=False)
    pays=models.TextField(blank=False,null=False)
    def __str__(self):
        return self.numV
        return self.complementdest
        return self.complementadr
        return self.commune
        return self.codeP
        return self.pays
    def __Adr__(self):
        return self.adr1.all()

and

class CompteCandidat(myUser):
    sexe = models.TextField(max_length=10)
    datecr = models.DateTimeField(auto_now_add = True)
    adresse=models.OneToOneField('Adresse',related_name='adr1',null=True, default=None)
    def __str__(self):
        return self.first_name
        return self.last_name
        return self.email
        return self.sexe
    def __Adr__(self):
        return self.adresse.all()

I try to do some tests like this:

adresse=Adresse(numV='254',complementdest='xxxxx',complementadr='Eugene napoleon',commune='Paris',codeP='75012',pays='France')

c1=CompteCandidat(username='Luna',first_name='celia',last_name='durand',password='CCC',email='hello2@gmail.com',type='candidat',adresse=adresse) adresse.save() c1.save()

and when I try to see what I have in my Adresse or in my CompteCandidat by using this command it didn't work

>>> Adresse.__getattribute__(numV)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'numV' is not defined

i want to know what i'm suppose to do to display what I have in Adresse and CompteCandidat in order to be sure that the add works

i know i Can do :

>>> adresse.numV
'254'

but it works only in the console there is an another way to consult all the database without using the name of the temporery variables ????

Aucun commentaire:

Enregistrer un commentaire