How to use get_fields method in Kiwi

Best Python code snippet using Kiwi_python

admin.py

Source:admin.py Github

copy

Full Screen

...7from django.contrib.gis import admin8from django.contrib.admin.widgets import AdminFileWidget9from django.utils.safestring import mark_safe10from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter, PolymorphicInlineSupportMixin, StackedPolymorphicInline11def get_fields(model: models.Model):12 exclude = DEFAULT_EXCLUDE + ['artifact_ptr',]13 fields = [field for field in diana.abstract.models.get_fields(model) if ((not field.startswith('legacy')) and field not in exclude)]14 return fields15def get_list_display_fields(model: models.Model):16 m2m = get_many_to_many_fields(model)17 exclude = DEFAULT_EXCLUDE + ['artifact_ptr',]18 fields = [field for field in diana.abstract.models.get_fields(model) if ((not field.startswith('legacy')) and field not in exclude and field not in m2m)]19 return fields + DEFAULT_FIELDS20##########################################21class AdminImageWidget(AdminFileWidget):22 def render(self, name, value, attrs=None, renderer=None):23 output = []24 if value and getattr(value, "url", None):25 image_url = value.url26 file_name = str(value)27 output.append(28 f'<a href="{image_url}" target="_blank">'29 f'<img src="{image_url}" alt="{file_name}" width="150" height="150" '30 f'style="object-fit: cover;"/> </a>')31 output.append(super(AdminFileWidget, self).render(name, value, attrs, renderer))32 return mark_safe(u''.join(output))33class ImageInline(admin.StackedInline):34 model = Image35 formfield_overrides = {models.ImageField: {'widget': AdminImageWidget}}36 exclude = ('iiif_file',)37 extra = 138@admin.register(ImageContent)39class ImageContentTagAdmin(admin.ModelAdmin):40 fields = get_fields(ImageContent)41 list_display = get_fields(ImageContent) + DEFAULT_FIELDS42@admin.register(Material)43class MaterialAdmin(admin.ModelAdmin):44 fields = get_fields(Material)45 list_display = get_fields(Material) + DEFAULT_FIELDS46@admin.register(Place)47class PlaceAdmin(admin.ModelAdmin):48 fields = get_fields(Place)49 list_display = get_fields(Place) + DEFAULT_FIELDS50@admin.register(Person)51class PersonAdmin(admin.ModelAdmin):52 fields = get_fields(Person)53 list_display = get_fields(Person) + DEFAULT_FIELDS 54 search_fields = ('name',)55@admin.register(Image)56class ImageModel(admin.ModelAdmin):57 58 fields = get_fields(Image)59 readonly_fields = ['uuid', 'iiif_file']60 list_display = get_list_display_fields(Image)61 filter_horizontal = ('tags',)62@admin.register(Museum)63class MuseumAdmin(admin.ModelAdmin):64 fields = get_fields(Museum)65 list_display = get_fields(Museum) + DEFAULT_FIELDS 66 search_fields = ('name',)67##################################################68class ArtifactAdminModel(PolymorphicInlineSupportMixin, PolymorphicChildModelAdmin):69 base_model = Artifact70 search_fields = ['title']71 show_in_index = True72 inlines = [ImageInline,]73 filter_horizontal = ('materials', 'persons', 'places')74@admin.register(Artwork)75class ArtworkAdmin(ArtifactAdminModel):76 base_model = Artwork77 fields = get_fields(Artwork)78 list_display = get_list_display_fields(Artwork)79 # filter_horizontal = ('materials',)80 autocomplete_fields = ('creator', 'museum')81@admin.register(Photograph)82class PhotographAdmin(ArtifactAdminModel):83 base_model = Photograph84 fields = get_fields(Photograph)85 list_display = get_list_display_fields(Photograph)86 autocomplete_fields = ('creator', 'museum')87@admin.register(Letter)88class LetterAdmin(ArtifactAdminModel):89 base_model = Letter90 fields = get_fields(Letter)91 list_display = get_list_display_fields(Letter)92 autocomplete_fields = ('sender', 'recipient', 'museum')93@admin.register(Document)94class DocumentAdmin(ArtifactAdminModel):95 base_model = Document96 fields = get_fields(Document)97 list_display = get_list_display_fields(Document)98 autocomplete_fields = ('museum',)99@admin.register(Relic)100class RelicAdmin(ArtifactAdminModel):101 base_model = Relic102 fields = get_fields(Relic)103 list_display = get_list_display_fields(Relic)104 autocomplete_fields = ('museum',)105@admin.register(Artifact)106class ArtifactParentAdmin(PolymorphicParentModelAdmin):107 """ The parent model admin """108 base_model = Artifact # Optional, explicitly set here.109 child_models = (Artwork, Photograph, Letter, Document, Relic)...

Full Screen

Full Screen

forms.py

Source:forms.py Github

copy

Full Screen

...3class CardForm(ModelForm):4 class Meta:5 model = Card6 fields = '__all__'7 widgets = {f.name: TextInput() for f in Card._meta.get_fields()}8class TransactionForm(ModelForm):9 class Meta:10 model = Transaction11 fields = '__all__'12 widgets = {f.name: TextInput() for f in Transaction._meta.get_fields()}13class AccountForm(ModelForm):14 class Meta:15 model = Account16 fields = '__all__'17 widgets = {f.name: TextInput() for f in Account._meta.get_fields()}18class BankaccountForm(ModelForm):19 class Meta:20 model = Bankaccount21 fields = '__all__'22 widgets = {f.name: TextInput() for f in Bankaccount._meta.get_fields()}23class CreatebankaccountrequestForm(ModelForm):24 class Meta:25 model = Createbankaccountrequest26 fields = '__all__'27 widgets = {f.name: TextInput() for f in Createbankaccountrequest._meta.get_fields()}28class CreatecardrequestForm(ModelForm):29 class Meta:30 model = Createcardrequest31 fields = '__all__'32 widgets = {f.name: TextInput() for f in Createcardrequest._meta.get_fields()}33class DepositForm(ModelForm):34 class Meta:35 model = Deposit36 fields = '__all__'37 widgets = {f.name: TextInput() for f in Deposit._meta.get_fields()}38class EmployeeForm(ModelForm):39 class Meta:40 model = Employee41 fields = '__all__'42 widgets = {f.name: TextInput() for f in Employee._meta.get_fields()}43class EmployeescheduleForm(ModelForm):44 class Meta:45 model = Employeeschedule46 fields = '__all__'47 widgets = {f.name: TextInput() for f in Employeeschedule._meta.get_fields()}48class PaybillForm(ModelForm):49 class Meta:50 model = Paybill51 fields = '__all__'52 widgets = {f.name: TextInput() for f in Paybill._meta.get_fields()}53class PurchaseForm(ModelForm):54 class Meta:55 model = Purchase56 fields = '__all__'57 widgets = {f.name: TextInput() for f in Purchase._meta.get_fields()}58class QarzolhasanaForm(ModelForm):59 class Meta:60 model = Qarzolhasana61 fields = '__all__'62 widgets = {f.name: TextInput() for f in Qarzolhasana._meta.get_fields()}63class RealpersonForm(ModelForm):64 class Meta:65 model = Realperson66 fields = '__all__'67 widgets = {f.name: TextInput() for f in Realperson._meta.get_fields()}68class SavingForm(ModelForm):69 class Meta:70 model = Saving71 fields = '__all__'72 widgets = {f.name: TextInput() for f in Saving._meta.get_fields()}73class SupportForm(ModelForm):74 class Meta:75 model = Support76 fields = '__all__'77 widgets = {f.name: TextInput() for f in Support._meta.get_fields()}78class UserrequestForm(ModelForm):79 class Meta:80 model = Userrequest81 fields = '__all__'82 widgets = {f.name: TextInput() for f in Userrequest._meta.get_fields()}83class WiretransferForm(ModelForm):84 class Meta:85 model = Wiretransfer86 fields = '__all__'87 widgets = {f.name: TextInput() for f in Wiretransfer._meta.get_fields()}88class WithdrawForm(ModelForm):89 class Meta:90 model = Withdraw91 fields = '__all__'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful