These are chat archives for django/django

20th
Jul 2018
Luke-VideoLibre
@LukeVideo
Jul 20 2018 07:11
I'm using a custom form for a models creation. A can create my object no problem. If i edit the file i get the default admin panel. Is there a way of customising the edit view as well ?
Also the custom form has a file upload field but when i try to edit an Object i can't because i get an error. It seems to be an error caused by th efact i didn't upload a file. But ths field is only present when i create a file not when i edit/ change it.
devpahuja
@devpahuja
Jul 20 2018 09:10
Here is my template. I want to create a form for marking the attendance but I want the form to be in front of every students name. please help me. https://codepen.io/Dev10/pen/wXOoxj
I want to mark attendance every the button is clicked.
devpahuja
@devpahuja
Jul 20 2018 09:18
every time the button is clicked.
Curtis Maloney
@funkybob
Jul 20 2018 09:23
sounds a bit like a formset
devpahuja
@devpahuja
Jul 20 2018 09:23
I have created booleanfields for every student(checkbox)
but they are not visible in this way.
Curtis Maloney
@funkybob
Jul 20 2018 09:25
they don't appear to be in your template anywhere
matfire
@matfire
Jul 20 2018 14:22

Hello everyone,

I am creating a modular menu in Django that has the following structure;

class Pagina(models.Model):
nome = models.CharField(max_length=250, blank=True)
url = models.CharField(max_length=250)

def __str__(self):
    return self.nome

class Voce(models.Model):
nome = models.CharField(max_length=250, blank=True)
Pagine = models.ManyToManyField(Pagina)
Permesso = models.ForeignKey(Permesso, on_delete=models.CASCADE)

def __str__(self):
    return self.nome

class Menu(models.Model):
Voci = models.ManyToManyField(Voce)
I need to check if the user has the required permission to see the submenu(permission that is in a group).

The menu is rendered the following way;

{% for voce in menu.Voci.all %}
<li class="m-menu__item m-menu__item--submenu m-menu__item--rel {% ifequal parent voce.nome %}m-menu__item--active{% endifequal %}" m-menu-submenu-toggle="click" aria-haspopup="true">
<a href="javascript:;" class="m-menu__link m-menu__toggle">
<span class="m-menu__item-here"></span><span class="m-menu__link-text">{{voce}}</span><i class="m-menu__hor-arrow la la-angle-down"></i><i class="m-menu__ver-arrow la la-angle-right"></i>
</a>
<div class="m-menu__submenu m-menu__submenu--classic m-menu__submenu--left"><span class="m-menu__arrow m-menu__arrow--adjust"></span>
<ul class="m-menu__subnav">
{% for pagina in voce.Pagine.all %}
<li class="m-menu__item {% ifequal request.path pagina.url %}m-menu__item--active{% endifequal %}" aria-haspopup="true">
<a href="{{pagina.url}}" class="m-menu__link ">
<i class="m-menu__link-bullet m-menu__link-bullet--line"><span></span></i>
<span class="m-menu__link-title"><span class="m-menu__link-wrap"><span class="m-menu__link-text">{{pagina.nome}}</span></span></span>
</a>
</li>
{% endfor %}
</ul>
</div>
</li>
{% endfor %}
The check would need to happen just after the first for loop starts in order to determine whether or not to display that particular submenu.

The "gruppo" object of the user is a foreignkey relation to a personalized Group object, which has a ManyToMany relation with different permissions, each having a name. I need to check if a user has the same permission as the "Voce" model currently being looped through.

Can you guys help me?

Antonio Ognio
@aognio
Jul 20 2018 15:15
Hi everyone.. any idea where the string I assign to the related_name parameter in, say, a ForeignKey field goes once the field is instantiated? e.g. if you want to test if it has the right value...
Oh nevermind, I found it.. it's in the your_fk_field.rel.related_name attribute.