0

I want to pass name and the user fields should be current user who creating the records.

This is my models

class TestModel(models.Model):
    user = models.ForeignKey(
        User,
        on_delete=models.CASCADE,
        related_name="test"
    )
    name = models.CharField(
        max_length=255,
        verbose_name=_('test name'),
    )
    panels = [
        FieldPanel('name'),
    ]

and this is my wagtail_hooks.py file

class TestAdmin(ModelAdmin):
    model = TestModel
    menu_label = 'Test' 
    menu_icon = 'doc-full-inverse'
    list_display = ('name', 'owner',)
    list_filter =  ('name', 'owner',)
    search_fields =  ('name', 'owner',)

 
modeladmin_register(TestAdmin)

Does anyone know how can I save with current authenticated user as the user instance can found with request.user

But i am not getting how to asign the user from server during create? I want only user will send name from wagtail admin, and the user fields name passed in server with current user instance.

How can i do it in wagtail modelamdin?

0 Answers0