0
0 комментариев

Добрый день. Нужно вывести из бд значения на страничку. Столкнулся с проблемой:
при выводе значение с полем ManyToManyField выдает такое: app.AuthUser.None, хотя поле не пустое…

модель:

class AuthUser(AbstractBaseUser, PermissionsMixin):
    alphanumeric = RegexValidator(r'^[0-9a-zA-Z]*$', message='Only alphanumeric characters are allowed.')
    username = models.CharField(unique=True, max_length=30, validators=[alphanumeric])
    email = models.EmailField(verbose_name='email field', unique=True, max_length=255)
    first_name = models.CharField(max_length=50, null=True, blank=True)
    second_name = models.CharField(max_length=50, null=True, blank=True)
    last_name = models.CharField(max_length=50, null=True, blank=True)
    # date_joined = models.DateTimeField(auto_now_add=True)
    date_joined = models.DateTimeField(default=timezone.now())
    is_active = models.BooleanField(default=True, null=False)
    is_staff = models.BooleanField(default=False, null=False)
    # profile_image = models.ImageField(upload_to='uploads', blank=False, default='/static/selfphoto.jpg')
    user_bio = models.TextField()
    perm = models.IntegerField(default=0)
    podr = models.IntegerField(default=0)
    dolznost = models.CharField(max_length=30, null=True, blank=True)
    objects = AuthUserManager()
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']
    def get_full_name(self):
        return '%s %s %s' .format(self.last_name, self.first_name, self.second_name)
    def get_short_name(self):
        return self.username
    def __str__(self):
        return '%s %s %s %s %s' % (self.last_name, self.first_name, self.second_name, self.podr, self.dolznost)
class Karto(models.Model):
    idname = models.IntegerField(default=0, blank=True, null=True)
    datecreated = models.DateTimeField(default=timezone.now())
    small = models.CharField(max_length=255, blank=True)
    file = models.FileField(upload_to='uploads', blank=True)
    soglas = models.ManyToManyField(AuthUser)
    madeby = models.CharField(max_length=30, blank=True, null=True)
    class Meta:
        ordering = ["idname"]

[/apcode]

вьюха:

def docsupdocs(request, idname):
    args = {}
    args['perm'] = request.user.perm
    args['myq'] = Karto.objects.get(idname=idname)
    return render_to_response('self_docsupdocs.html', args, context_instance=RequestContext(request))

поле заполнял через админку:

class KartoAdmin(admin.ModelAdmin):
    model = Karto
    fields = ['idname', 'small', 'file', 'datecreated', 'soglas', 'madeby']
    filter_horizontal = ['soglas',]

html:

{% block owned %}

allah

{{ myq.small }}
{{ myq.madeby }}
{{ myq.datecreated }}

{{ myq.soglas }} {% endblock %}

[/apcode]

результат:

allah
 
betta test
max
5 ноября 2015 г. 11:11
 
app.AuthUser.None


Добавить комментарий