Here I am trying to register log if the new category has been created. But this is not working.I am using generic View to create the category model now I want to add LogEntry to this model so tried like this but it is throwing error.
Exception Type: AttributeError
Exception Value:
'CreateCategory' object has no attribute 'object'
views
class CreateCategroy(SuccessMessageMixin, generic.CreateView):
model = Category
fields = ['title']
template_name = 'add_category.html'
success_url = reverse_lazy('list_category')
success_message = 'Created Successfully.'
def post(self, request, *args, **kwargs):
LogEntry.objects.log_action(user_id=self.request.user.pk,
content_type_id=ContentType.objects.get_for_model(Category).pk,
object_id=self.object.pk,
object_repr=force_text(self.object),
change_message='New Category has been created.',
action_flag=1
)