问题
I'm creating wagtail website that copies and adds to the functionality of old django website: there is a blog-like "animal-listing" and "plant-listing" pages with post-detail-like "animal detail" and "plant detail" pages. They share a common "need" tag via simple ManyToManyField, because animals and plants have some of the same needs (like water or hay). Need tags are displayed on the "needs page" table, which has columns like "store link". This original solution weren't as smooth as autocomplete tag fields in wagtail so I'm trying to recreate the same thing in wagtail, but I don't know how to link wagtail's TaggableManager/TagItemBase to a separate model and make it have fields like "item link". I also have no idea how to make wagtail tag field give user a popup every time a non-existing tag is added (this was old django implementation, see the picture below).
Here's the original django models.py
from django.db import models
from django.contrib.auth.models import User
class Animal(models.Model):
name = models.CharField(max_length=100)
picture = models.ImageField(upload_to='./media/pictures-animals/', null=True, blank=True, default=None)
description = models.TextField(max_length=10000)
adoption_reason = models.TextField(max_length=1000)
needs = models.ManyToManyField('Need', related_name='animals')
def __str__(self):
return f'{self.name}'
class Plant(models.Model):
species = models.CharField(max_length=100)
picture = models.ImageField(upload_to='./media/pictures-plants/', null=True, blank=True, default=None)
description = models.TextField(max_length=10000)
needs = models.ManyToManyField('Need', related_name='plants')
entry_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f'{self.species}'
class Need(models.Model):
title = models.CharField(max_length=100)
link = models.URLField(max_length=1000, null=True, blank=True, default="None")
def __str__(self):
return f'{self.title}'
And this is what I mean by "pretty wagtail field" : In an answer to my previous, related question, I was told I should keep the wagtail "taggedItemBase" models separate since they both will just link to taggit.Tag, so now I'm confused.
来源:https://stackoverflow.com/questions/61782154/additional-fields-associated-with-wagtail-tags