In the project manage app I'm working on it should be possible to edit/delete a ticket if you are the owner of (i.e. the creator of) the ticket and/or the admin of the project the ticket belongs to.
In the template for showing a project I want to use a custom filter to determine this, used as seen here:
{% if ticket|owner_or_admin:user %}
<p>
<a href="{% url ticket_edit project.id %}">Edit</a>
<a id="delete_link" href="{% url ticket_delete ticket.id %}">Delete</a>
</p>
{% endif %}
Below is a try of creating this custom filter, but this throws an error ('owner_or_admin requires 2 arguments, 1 provided'):
@register.filter(name='owner_or_admin')
def ownership(ticket, project, user):
if ticket.user == user:
return true;
else:
if project.added_by_user == user:
return true
return false
models:
class Project(models.Model):
... fields ...
added_by_user = models.ForeignKey(User)
class Ticket(models.Model):
... fields ...
user = models.ForeignKey(User)
So, how do I provide two arguments? Is the custom filter correct otherwise?
Thanks in advance!