I am creating a file upload page which has a file upload model:
models.py
class Upload(models.Model):
file = models.FileField(blank=True, null=True, validators=[validate_file_extension])
upload_date = models.DateTimeField(auto_now_add=True)
class Meta:
permissions = (
('can_upload_x', 'Can Upload X'),
('can_upload_y', 'Can Upload Y'),
('can_upload_z', 'Can Upload Z'),
)
forms.py
class UploadFileForm(forms.ModelForm):
class Meta:
model = Upload
fields = ['file']
html
{% if perms.app.can_upload_x %}
<form action="#" method="post" enctype="multipart/form-data">
<input type='hidden' name='action' value='x'>
{% csrf_token %} {{form_x}}
<input type="submit" value="Upload" id="weights_btn" name="weights_btn"
class="btn btn-default btn-file"/>
</form>
{%endif%}
#etc for X, Y, Z, ....
So the end goal is for the users assigned to have certain permissions from the admin like 'can_upload_x' will only be able to see the form for X etc ( I make different forms save to different locations with handle_uploaded_file in the views).
What am I doing wrong? does not seem to work. It did, however work when I had a model for each form but it is unfeasible for my project since I might have to have a whole lot of different forms.
Thank you!