Django给postjob限制

时间:2013-04-08 05:06:00

标签: django

在EmployerRegistration和PostJob等数据库中有表格。我将这些表与empid(PostJob的外键)联系起来。使用这个empid我需要PostJob最多5.我想显示警报消息,如登录时可用的帖子数量。有人帮助如何为这种情况提供观点。

models.py
class EmployerRegistration(models.Model):
    username=models.CharField(max_length=30)
    password=models.CharField(max_length=30)

class PostJob(models.Model):
    emp = models.ForeignKey(EmployerRegistration)
    jobtitle = models.CharField(max_length=30)
    jobsummary = models.TextField()
    key_skills = models.CharField(max_length=30)
    experince = models.IntegerField(default=0)
    salary = models.IntegerField(default=0)

1 个答案:

答案 0 :(得分:1)

views.py

def your_view(request, empid):
    msg=""

    if request.method == "POST":
        jobs = PostJob.objects.filter(emp_id=empid).count()
        if jobs <= 5:
            //save
        else:
            msg = Your not allow to add new post job. 

    return render(request, 'page.html', {'msg': msg})

模板

<script>
    $(document).ready(function(){
        var msg = {{msg}}
        if(msg != ""){
            alert(msg);
        }
    });
</script>