Best Python code snippet using Kiwi_python
admin.py
Source:admin.py
...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)...
forms.py
Source:forms.py
...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__'...
Check out the latest blogs from LambdaTest on this topic:
Hey LambdaTesters! We’ve got something special for you this week. ????
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!