I need to create an journal like application, where users can submit papers
and those papers can be reviewed. My code is publicly available on github
and the app is about ~50 done.

The reviewers should also be users of the same app and they should be able
to comment and perhaps give a rating. (I will create a model for this later)

How can I achieve that?

How do I restrict the Paper model only to the Author (the user who
submitted it), the Admins and the Reviewers?


```

from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from .validators import FileValidator


# This function is used by the Paper model class.
def user_id_path(instance, filename):
    """
    Constructs a path of the type /papers/<user_id>_<username>/<paper
title>/<filename>

    instance: The instance provide dy django
    filename: The filename provided by django

    returns: A string containing the path of the uploaded paper.
    """
    return "papers/{0}_{3}/{1}/{2}".format(instance.user.id,
instance.title, filename, instance.user.username)


class Paper(models.Model):
    STATUS_CHOICES = (
        ('processing', 'Processing'),
        ('under_review', 'Under Review'),
        ('preliminary_reject', 'Preliminary Reject'),
        ('accepted', 'Accepted'),
    )
    user = models.ForeignKey(User, related_name='papers')
    title = models.CharField(max_length=64, blank=False)
    description = models.TextField(max_length=2000, blank=False)
    authors = models.TextField(max_length=4096)
    created = models.DateTimeField(auto_now_add=True)
    status = models.CharField(max_length=64, choices=STATUS_CHOICES,
default='processing')
    # File validator.
    validate_file = FileValidator(max_size=1024 * 1024 * 50,  # Max size is 50Mb
                                  content_types=('application/pdf',
'text/html', 'application/msword',

'application/vnd.openxmlformats-officedocument.wordprocessingml.'
                                                 'document',
                                                 'text/plain',))
    manuscript = models.FileField(upload_to=user_id_path, blank=False,
validators=[validate_file])
    cover_letter = models.FileField(upload_to=user_id_path,
blank=False, validators=[validate_file])
    supplementary_materials = models.FileField(upload_to=user_id_path,
blank=True, null=True, default=None,
                                               validators=[validate_file])

    class Meta:
        ordering = ('-created',)

    def get_absolute_url(self):
        return reverse('journal.views.details', args=[str(self.id)])

    def __str__(self):
        return self.title

```
-- 
Sincerely,
Denis Nutiu

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKUfvewRANo4qSrHyFAPLbWg32P9Be8G-UZ1sZCG8rfJqg-9ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to