我试图在码头工人中创建一个容器;它通常工作得很好,但我突然遇到一个问题,我知道如何解决。
class MyModelAdmin(admin.ModelAdmin):
list_display = ['name',
'foo',
'active',
'created',
'started',
'ended']
list_editable = ['name',
'active',
'ended']
def formfield_for_dbfield(self, db_field, *args, **kwargs):
if db_field.name.lower() == 'foo':
choices = sorted(some_dynamic_list)
db_field.choices = choices
return super().formfield_for_dbfield(db_field, *args, **kwargs)
def get_changelist_form(self, request, *args, **kwargs):
parent_form = super().get_changelist_form(request, *args, **kwargs)
return self.get_childform(parent_form)
def get_form(self, request, obj=None, *args, **kwargs):
parent_form = super().get_form(request, obj, *args, **kwargs)
return self.get_childform(parent_form, obj)
def get_childform(self, parent_form, obj=None):
class ChildForm(parent_form):
def clean(self, *args, **kwargs):
instance_dict = {}
for instance in MyModel.objects.filter(active=True):
foo = instance.config_type.lower()
if foo in instance_dict:
instance_dict[foo].append(instance)
else:
instance_dict[foo] = [instance, ]
if not obj:
for foo, instances in instance_dict.items():
for list_index, instance in enumerate(instances):
for other_instance in instances[list_index + 1:]:
if self.instances_conflict(instance, other_instance):
raise forms.ValidationError("Instances of the same type must not overlap!")
else:
for instance in instance_dict[obj.foo]:
if instance is not obj:
if self.instances_conflict(obj, instance):
raise forms.ValidationError("Instances of the same type must not overlap!")
return super().clean(*args, **kwargs)
def instances_conflict(self, instance_1, instance_2):
if instance_1.ended is None and instance_2.started > instance_1.started:
return True
if instance_2.ended is None and instance_1.started > instance_2.started:
return True
if instance_1.started > instance_2.started and instance_1.started < instance_2.ended:
return True
if instance_2.started > instance_1.started and instance_2.started < instance_1.ended:
return True
return False
return ChildForm
当它进入apt-get update时会抛出以下错误:
如果图像基于标准的ubuntu 14.04,这怎么可能?
答案 0 :(得分:5)
您没有使用&&
结束apt-get upgrade命令,因此它尝试在以下行安装“packages”。我喜欢将&&
放在每行的开头,因为我更容易看到发生这种情况(并使复制/粘贴更容易):
FROM ubuntu:14.04
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
openssh-server \
&& mkdir /var/run/sshd
RUN echo root:root | chpasswd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
答案 1 :(得分:0)
这很有效。
public static void main(String[] args) {
JFrame fram = new JFrame();
yesnoPanel question = new yesnoPanel("are you ok");
JPanel q = question.getQuestion();
JPanel a = question.getAnsw();
JPanel all = new JPanel();
all.add(q);
all.add(a);
yesnoPanel question2 = new yesnoPanel("sure ?");
JPanel q2 = question2.getQuestion();
q2.setSize(200,500);
JPanel a2 = question2.getAnsw();
JPanel all2 = new JPanel();
all2.add(q2,BorderLayout.WEST);
all2.add(a2);
JScrollPane scroll = new JScrollPane();
scroll.setPreferredSize(new Dimension(100,100));
scroll.setViewportView(all);
scroll.setVisible(true);
}