在这里,我有一个模型Staff,它与 djangoUser模型有 OneToOne 关系,与模型有外键关系。在Organization这里删除组织时,我想检查组织是否存在于 Staff 模型中。如果它存在于 Staff 模型中,那么我不想删除但如果它不存在于其他表中,那么只有我想删除。
我该怎么做 ?
我使用以下代码收到此错误:
Exception Type: TypeError
Exception Value:
argument of type 'bool' is not iterable
Run Code Online (Sandbox Code Playgroud)
模型.py
class Organization(models.Model):
name = models.CharField(max_length=255, unique=True)
slug = AutoSlugField(unique_with='id', populate_from='name')
logo = models.FileField(upload_to='logo', blank=True, null=True)
class Staff(models.Model):
user = models.OneToOneField(get_user_model(), on_delete=models.CASCADE, related_name='staff')
name = models.CharField(max_length=255, blank=True, null=True)
organization = models.ForeignKey(Organization, on_delete=models.SET_NULL, blank=True, null=True,
related_name='staff')
Run Code Online (Sandbox Code Playgroud)
视图.py
def delete_organization(request, pk):
organization = get_object_or_404(Organization, pk=pk)
if organization in organization.staff.all().exists():
messages.error(request,"Sorry can't be deleted.") …Run Code Online (Sandbox Code Playgroud) 这里我有一些模型,这个模型应该有一些标签以使其对 SEO 友好。为此我该如何设计我的模型?
任何建议或帮助将不胜感激。
我的模特
class TourPackage(models.Model):
name = models.CharField(max_length=255)
package_detail = models.TextField()
image = models.ImageField()
booking_start = models.DateTimeField()
booking_end= = models.DateTimeField()
package_start = models.DateTimeField()
#how can i save this tag field for seo purpose
#tag = models.CharField()
Run Code Online (Sandbox Code Playgroud)