Revisions
-
SmileyChris revised this gist
Jan 2, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,4 @@ def add_job(request): msg = "Job saved successfully" messages.success(request, msg, fail_silently=True) return redirect(article) return render(request, 'job/job_form.html', {'form': form}) -
SmileyChris revised this gist
Jan 2, 2013 . 2 changed files with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,14 @@ class JobForm(forms.ModelForm): """ A form used for creating a Job. It handles the start_time and end_time defaults. """ class Meta: fields = [] # Everything except 'slug' and 'author'. model = Job def save(self, *args, **kw): last_entry = self.instance.author.job_set.aggregate(max_end_time=Max('end_time'))['max_end_time'] if last_entry: self.instance.start_time = last_entry.end_time return super(JobForm, self).save(*args, **kw) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,4 @@ def add_job(request): msg = "Job saved successfully" messages.success(request, msg, fail_silently=True) return redirect(article) return render('job/job_form.html', {'form': form}) -
SmileyChris revised this gist
Jan 2, 2013 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ class Meta: model = Job def save(self, *args, **kw): last_entry = self.instance.author.job_set.aggregate(max_end_time=Max('end_time'))['max_end_time'] if last_entry: self.instance.start_time = last_entry.end_time return super(JobForm,self).save(*args, **kw) -
SmileyChris revised this gist
Jan 2, 2013 . 3 changed files with 21 additions and 49 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ class JobForm(forms.ModelForm): """ this handles the start_time and end_time defaults""" class Meta: exclude = ['slug','author',] model = Job def save(self, *args, **kw): last_entry = Job.objects.filter(author=self.request.user).aggregate(max_end_time=Max('end_time'))['max_end_time'] if last_entry: self.instance.start_time = last_entry.end_time return super(JobForm,self).save(*args, **kw) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,52 +12,3 @@ Exception Type: IntegrityError Exception Value: (1048, "Column 'author_id' cannot be null") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ @login_required def add_job(request): form = JobForm(data=request.POST or None) if form.is_valid(): form.instance.author = request.user article = form.save() msg = "Job saved successfully" messages.success(request, msg, fail_silently=True) return redirect(article) return render('job/job_form.html', { 'form': form }) -
thebookworm101 revised this gist
Jan 2, 2013 . 1 changed file with 0 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,18 +61,3 @@ class JobForm(forms.ModelForm): -
thebookworm101 revised this gist
Jan 2, 2013 . 1 changed file with 18 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,21 @@ ################entering some data the first time to my form doesnt work, it gives this error: IntegrityError at /job/add/article/ (1048, "Column 'author_id' cannot be null") Request Method: POST Request URL: http://localhost:8000/job/add/article/ Django Version: 1.4.3 Exception Type: IntegrityError Exception Value: (1048, "Column 'author_id' cannot be null") #########################Problem im solving: im trying to set the begin_time to be the same as the end_time of the previous entry of this model by the same user if any (only the very first time wont have a previous end_time). ###Here is my solution i have so far: #######################The view ######### @@ -41,20 +58,7 @@ class JobForm(forms.ModelForm): instance.save() return instance -
thebookworm101 created this gist
Jan 2, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ ###Problem, im trying to set the begin_time to be the same as the end_time of the previous entry of this model by the same user if any (only the very first time wont have a previous end_time). ###Here is my solution i have so far: #######################The view ######### @login_required def add_job(request): form = JobForm(request.POST or None) if form.is_valid(): article = form.save(commit=False) article.author = request.user article.save() msg = "Job saved successfully" messages.success(request, msg, fail_silently=True) return redirect(article) return render_to_response('job/job_form.html', { 'form': form }, context_instance=RequestContext(request)) ######################the JobForm ######### class JobForm(forms.ModelForm): """ this handles the start_time and end_time defaults""" class Meta: exclude = ['slug','author',] model = Job def __init__(self,*args, **kw): super(JobForm,self).__init__( *args, **kw) def save(self, *args, **kw): instance = super(JobForm,self).save() #last_entry = Job.objects.filter(author__id=user.id).order_by('-id')[0] last_entry = Job.objects.filter(author=self.request.user).aggregate(max_end_time=Max('end_time'))['max_end_time'] if last_entry: instance.start_time = last_entry.end_time else: # this is the very first record do nothing pass instance.save() return instance ################But on entering some data the first time it doesnt work, it gives this error: IntegrityError at /job/add/article/ (1048, "Column 'author_id' cannot be null") Request Method: POST Request URL: http://localhost:8000/job/add/article/ Django Version: 1.4.3 Exception Type: IntegrityError Exception Value: (1048, "Column 'author_id' cannot be null") ################### here is the model , class Job(models.Model): """""" start_time = models.DateTimeField(default=datetime.datetime.now(),) end_time= models.DateTimeField( help_text="YYYY-MM-DD HH-MM-SS") activity = models.CharField(max_length=255) task = models.CharField(max_length=100) category= models.CharField(max_length=1,choices=MY_CATEGORIES,default='A') subcategory = models.CharField(max_length=1,choices=MY_SUBCATEGORIES,default='A') slug = models.SlugField(max_length=50, unique=True) # author = models.ForeignKey(User) objects = models.Manager()