如何在表单字段之间添加一些html文本?这是我的forms.py:
page_controller.controller('open_orderController', [
'$scope', '$rootScope', '$routeParams', '$http', '$global', '$location', '$filter', '$modal', '$bootbox',
'DTOptionsBuilder', 'DTColumnBuilder', '$q', '$compile',
function($scope, $rootScope, $routeParams, $http, $global, $location, $filter, $modal, $bootbox,DTOptionsBuilder,
DTColumnBuilder, $q, $compile) {
$scope.timeFormData = {};
$scope.my_parent_function = function()
{
$scope.timeFormData.text = "hello wordd";
}
$scope.child_controller = function()
{
var modalInstance = $modal.open({
templateUrl: 'time_change.html',
controller: function($scope, $modalInstance) {
$scope.change_timeFormData = {};
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
},
size: 'mg',
resolve: {
}
});
}
}]);
我的html文件的一部分:
class SiteAddFormFull(forms.ModelForm):
url = forms.URLField(widget=forms.TextInput(attrs={'readonly': 'readonly'}))
class Meta:
model = Site
fields = ('url', 'name', 'description', 'keywords', 'group', 'category',
'subcategory', 'category1', 'subcategory1', 'email')
def clean(self):
cleaned_data = super().clean()
subcategory = cleaned_data['subcategory']
subcategory1 = cleaned_data['subcategory1']
if subcategory1 and (subcategory == subcategory1):
raise forms.ValidationError("Subcategories can't be the same.")
我想在'group'字段后添加说明。类似的东西:
只是普通的html文字。我怎样才能做到这一点?
答案 0 :(得分:2)
您可以在模型的组字段中添加help_text
属性:
class Site(models.Model):
group = models.<FieldType>(..., help_text="You can add site to 2 categories")
答案 1 :(得分:1)
答案 2 :(得分:0)
确定。我这样做了:
group = models.CharField(max_length=10, choices=(('podstawowy', 'podstawowy'),
('premium', 'premium')), default='podstawowy',
help_text="<div id='group'><ul><li>You can add site to 2 <b>categories</b></li></ul></div>")
这里还有其他问题。如果将有3,4,5行html代码,这里的代码将会出现问题。我该怎么写呢?是否可以在外部文件中包含一些html文本。也许是另一种解决方案?