Skip to content

Commit

Permalink
Fix issue with the refactoring of user and user profile model
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Vargas committed Mar 17, 2016
1 parent 943ea72 commit aae8349
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
8 changes: 4 additions & 4 deletions qa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def __str__(self):

class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
pub_date = models.DateTimeField('date published', auto_now_add=True)
tags = models.ManyToManyField(Tag)
reward = models.IntegerField(default=0)
views = models.IntegerField(default=0)
user_data = models.ForeignKey(settings.AUTH_USER_MODEL)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
closed = models.BooleanField(default=False)

def __str__(self):
Expand All @@ -46,7 +46,7 @@ class Answer(models.Model):
answer_text = MarkdownField()
votes = models.IntegerField(default=0)
pub_date = models.DateTimeField('date published')
user_data = models.ForeignKey(settings.AUTH_USER_MODEL)
user = models.ForeignKey(settings.AUTH_USER_MODEL)

def __str__(self):
return self.answer_text
Expand All @@ -66,7 +66,7 @@ class Comment(models.Model):
answer = models.ForeignKey(Answer)
comment_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
user_data = models.ForeignKey(settings.AUTH_USER_MODEL)
user = models.ForeignKey(settings.AUTH_USER_MODEL)

def __str__(self):
return self.comment_text
25 changes: 11 additions & 14 deletions qa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,26 @@ def add(request):
question_text = request.POST['question']
tags_text = request.POST['tags']
user_id = request.POST['user']
user_ob = get_user_model().objects.get(id=user_id)
user = user_ob.userqaprofile
user = get_user_model().objects.get(id=user_id)

if question_text.strip() == '':
return render(request, 'qa/add.html', {'message': 'Empty'})

pub_date = datetime.datetime.now()
q = Question()
q.question_text = question_text
q.pub_date = pub_date
q.user_data = user
q.save()
question = Question()
question.question_text = question_text
question.user = user
question.save()

tags = tags_text.split(',')
for tag in tags:
try:
t = Tag.objects.get(slug=tag)
q.tags.add(t)
tag = Tag.objects.get(slug=tag)
question.tags.add(tag)
except Tag.DoesNotExist:
t=Tag()
t.slug = tag
t.save()
q.tags.add(t)
tag = Tag()
tag.slug = tag
tag.save()
question.tags.add(tag)

#send_mail('QA: Your Question has been Posted.', 'Thank you for posting the question, '+question_text+'. We will notify you once someone posts an answer.', '[email protected]', [request.user.email], fail_silently=False)

Expand Down

0 comments on commit aae8349

Please sign in to comment.