Skip to content

Instantly share code, notes, and snippets.

@nuty
Created August 13, 2014 09:19
Show Gist options
  • Save nuty/fe9deb23fd53f7b816d9 to your computer and use it in GitHub Desktop.
Save nuty/fe9deb23fd53f7b816d9 to your computer and use it in GitHub Desktop.
create edit view
@login_required(login_url='/admin/')
def ad_edit(request,id=None):
cities = City.objects.filter(status='1')
adzones = AdZone.objects.all()
channel_choices = Ad.get_channel_choices()
ad = get_object_or_none(Ad,pk=id)
is_edit = True if ad is not None else False
form = AdForm(instance=ad)
action = Log.ADDITION if ad is None else Log.CHANGE
if request.method == 'POST':
form = AdForm(request.POST,request.FILES,instance=ad)
if form.is_valid():
ad = form.save(commit=False)
ad.user_id = request.user.id
ad.update_date = datetime.now()
ad.save()
Log.set_log(request,ad,action)
return redirect(reverse('ad_index'))
return render(request,'ad/ad_edit.html',
{
"ad":ad,
"adzones":adzones,
"cities":cities,
"channel_choices":channel_choices,
"form":form,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment